在登录界面实现了用户名密码检查,为空时有提示
private void Button1_Click(object sender, EventArgs e)
{
string id = textBox1.Text.Trim().ToString();
string pw = textBox2.Text.Trim().ToString();
if (id == null || id.Length == 0 || pw == null || pw.Length == 0) {
MessageBox.Show("用户名或密码不能为空!");
return;
}
string connectionstring = "Data Source = D:\\sqlite\\db823.db";
SQLiteConnection connection = new SQLiteConnection(connectionstring);
connection.Open();
string sql = "select * from password where id = \"" + id + "\"";
SQLiteDataAdapter da = new SQLiteDataAdapter(sql, connection);
DataSet ds = new DataSet();
if (da != null) {
da.Fill(ds);
DataTable dt = ds.Tables[0];
if (dt == null || dt.Rows == null || dt.Rows.Count == 0 || dt.Rows[0][1] == null || !dt.Rows[0][1].Equals(pw))
{
MessageBox.Show("密码不匹配,请重试");
return;
}
else
{
MessageBox.Show("密码匹配");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
}
}
todo:
1、封装数据库相关操作类
2、数据结构SQLiteDataAdapter、DataSet、DataTable具体API都不太了解(这几个==null判断的我很无语)
下一步:
搜索页面多条显示搜索结果