
程序代码:
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "")
{
MessageBox.Show(null, "用户名和密码不能为空", "登陆失败", MessageBoxButtons.OK, MessageBoxIcon.Question);
return;
}
SqlConnection scon = new SqlConnection("server=GATEWAY-DING;database=njdl;uid=sa;pwd=sa");
DataSet ds = new DataSet();
string sql = "select count(*) as count from nj_user where name='" + textBox1.Text + "' and password='" + textBox2.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, scon);
da.Fill(ds);
string fieldvalue = ds.Tables[0].Rows[0]["count"].ToString();
int count = Convert.ToInt32(fieldvalue);
if (count != 0)
{
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show("用户名或密码不正确");
}
2楼的 改成 这样ok了...谢谢你们..