///数据库连接字符串没那么麻烦,一个字符串就搞定
string strConn = "Data Source=.;Initial CataLog=wujian;Integrated Security=True";
///使用using(…………) {} 可以象try{} catch(){} finally{} 那样避免错误
using ( SqlConnection thisConnection = new SqlConnection(strConn))
{
///主要错误出在这行,你的字符串拼接不对,少了单引号;
/// 字符串拼接拼接 推荐使用string.Format()
string sql = string.Format("select UserID,Password From ID_password where UserID ='{0}',Password='{1}' ",zhanghao.Text, mima.Text);
using ( SqlDataAdapter thisadapter = new SqlDataAdapter(sql, thisConnection))
{
DataSet thisDataset = new DataSet();
thisadapter.Fill(thisDataset, "ID_pssword");
if (thisDataset.Tables["ID_password"].Rows.Count == 0)
{
MessageBox.Show("用户名或密码错误!请重新登录!!!", "错误");
zhanghao.Clear();
mima.Clear();
zhanghao.Focus();
return;
}
else
{
Form2 xs = new Form2();
this.Hide();
xs.Show();
}
}