1 string strConnString = "server = (local); database = myStudy; uid = sa;pwd = ";
2 private void Button1_Click(object sender, System.EventArgs e)
3 {
4 SqlConnection conn = new SqlConnection(strConnString);
5 string sqlCmd = "select * from testuser where name ='"+this.TextBox1.Text.Trim()+"' and pwd = '"+this.TextBox2.Text.Trim()+"'";
6 SqlDataAdapter da = new SqlDataAdapter();
7 da.SelectCommand = new SqlCommand(sqlCmd,conn);
8 // SqlDataAdapter da = new SqlDataAdapter(sqlCmd,conn);
9 // DataTable tb = new DataTable();
10 DataSet ds = new DataSet();
11 da.Fill(ds);
12 if(ds.Tables[0].Rows.Count > 0 )
13 {
14 this.Label1.Text = "成功!";
15 }
16 else
17 {
18 this.Label1.Text = "失败!";
19 }
20
21 }
2 private void Button1_Click(object sender, System.EventArgs e)
3 {
4 SqlConnection conn = new SqlConnection(strConnString);
5 string sqlCmd = "select * from testuser where name ='"+this.TextBox1.Text.Trim()+"' and pwd = '"+this.TextBox2.Text.Trim()+"'";
6 SqlDataAdapter da = new SqlDataAdapter();
7 da.SelectCommand = new SqlCommand(sqlCmd,conn);
8 // SqlDataAdapter da = new SqlDataAdapter(sqlCmd,conn);
9 // DataTable tb = new DataTable();
10 DataSet ds = new DataSet();
11 da.Fill(ds);
12 if(ds.Tables[0].Rows.Count > 0 )
13 {
14 this.Label1.Text = "成功!";
15 }
16 else
17 {
18 this.Label1.Text = "失败!";
19 }
20
21 }