[宝典]登陆界面代码
登陆界面代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private static OleDbConnection oleConnection1 = null;
OleDbConnection connection=new OleDbConnection("Data Source=itasset.mdb;Jet OLEDB:Engine
Type=5;Provider=Microsoft.Jet.OLEDB.4.0;");
//获得数据库连接
public static OleDbConnection getConnection()
{
// if(oleConnection1==null)
// {
oleConnection1 = new OleDbConnection("Data
Source=itasset.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;");
oleConnection1.Open();
// }
return oleConnection1;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string mysql = "select * from userinfo where
UserID = '" + comboBox1.Text + "' and Password= '" + textBox1.Text + "'"; //Sql查询语句
OleDbDataAdapter myada = new OleDbDataAdapter(mysql, connection);
DataTable mydt = new DataTable();
myada.Fill(mydt);
int i = mydt.Rows.Count;
if (i >= 1)
{
Form2 myf = new Form2();
myf.Show();
this.closs(); //显示主界面
//myf.label1.Text = "欢迎 " + comboBox1.Text + " 登录主界面 ,其登录密码是: " + textBox1.Text;
}
else
{
MessageBox.Show("用户名或密码不正确,请重新输入~", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //提示对话框
comboBox1.Text = "";
textBox1.Text = "";
}
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (oleConnection1==null)
oleConnection1=Form1.getConnection();
//取出系统的所有用户名
//显示在下拉列
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
,这样用户登录的时候
//选择用户名就可以了,不用再输入用户名了
string sql="select UserID from userinfo";
OleDbCommand cmd = new
OleDbCommand(sql,oleConnection1);
OleDbDataReader dr = cmd.ExecuteReader();
int flag = 0;
while(dr.Read())
{
this.comboBox1.Items.Add(dr.GetString(0));
flag++;
}
//如果系统存在用户,则默认选中第一个用户
if (flag>0)
this.comboBox1.SelectedIndex=0;
dr.Close();
cmd.Dispose();
}
}
}