折腾了好久才做出来,请大家多多指教
刚开始是用int count=convert.int32(cmd.executeNoquery());做的,连接能够成功,但是总是提示用户名或密码错误。检查一下才知道应用
SqlDataReader read = cmd.ExecuteReader();
read.Read()
来判断用户名和密码是否正确!
//连接字符串string str="select count(*) from denglu where username='"+txtuser.Text+"' and password='"+txtpassword.Text+"'";
string strconn = "Data Source=YQL;Initial Catalog=studyhelper;Integrated Security=True;Pooling=False";
//用连接字符串创建数据库连接对象
SqlConnection con = new SqlConnection(strconn);
string str = "select * from Table2 where UserName like '" + tbName.Text.ToString() + " ' and Password = '" + tbPwd.Text.ToString() + " '";
SqlCommand cmd = new SqlCommand( str, con);
con.Open();
SqlDataReader read = cmd.ExecuteReader();
//read.Read()这个方法是返回bool的,如果查到数据就返回true。
if( read.Read())
{
this.Hide();//当前的界面隐藏
FrmMain main = new FrmMain();
main.Show();//主窗体显示
}

160

被折叠的 条评论
为什么被折叠?



