visual studio 2005连接SQL2000数据库,哪里出错啦。高手们指点下~
private void Form1_Load(object sender, EventArgs e){
string strConn = "server=.;user id=dbo;pwd=;database=admin";
SqlConnection con = new SqlConnection(strConn);
string sql = "select * from adminpswd";
SqlDataAdapter ada = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
ada.Fill(ds);
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.maskedTextBox1.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
else
{
if (IsUser(this.textBox1.Text))
{
if (this.maskedTextBox1.Text == LoginUser(this.textBox1.Text))
{
Form2 frm2 = new Form2();
// //frm2.showdialog();
frm2.Show();
Close();
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("用户名错误!");
}
}
}
private string LoginUser(string uName) //检测用户是否能够登录
{
DataSet ds = new DataSet();
return ds.adminpswd[0].Rows[0]["密码"].ToString();
con.Close();
}
private bool IsUser(string uName) //检测用户输入的用户名是否存在
{
DataSet ds = new DataSet();
ada.Fill(ds, "adminpswd");
int n;
n = ds.adminpswd[0].Rows.Count;
if (n > 0)
return true;//存在就返回true
else
return false;
con.Close();
}
private void button2_Click(object sender, EventArgs e)//button2的 Text属性是:取消登录
{
Application.Exit();//用户取消登录,退出系统
}