con = new SqlConnection(@"Data Source=owen\SQL2008;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;password=sa");
com = new SqlCommand("select * from StudentClass", con);
con.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
/*
就是就里怎么于登陆窗体的textbox1(用户名)和textbox2(密码)比较是否相等??
*/
}
dr.Close();
con.Close();怎么比较textbox1(用户名)和textbox2(密码)比较是否相等??
com = new SqlCommand("select * from StudentClass", con);
con.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
/*
就是就里怎么于登陆窗体的textbox1(用户名)和textbox2(密码)比较是否相等??
*/
}
dr.Close();
con.Close();怎么比较textbox1(用户名)和textbox2(密码)比较是否相等??
解决方案 »
- 找不到引用求助。
- 一段代码同时只能一个人执行
- 最近做个小东西 ,遇到了一些问题 ,希望诸位慷慨解囊
- VS2008不能解析VS2003的SLN
- vs2005 写了个读取文件的小程序,现在做成exe的安装文件,怎么做?
- 在radiobutton 中调用 treeview的aftercheck事件!
- 发现.Net 的一个有关Response.writeFile()相关的Bug,请求热心的哥们验证,或解决~~~
- 在资源管理器菜单中加入自定义的菜单项
- 请问:<?IMPORT namespace="dynMenu" implementation="menu.htc"> 在C#中怎么写?
- 我现在已经基本学会了C#的语法,请问接下去该如果学习比较好?
- 线程问题,再现等!!高手快快快
- 想问一下大家做winform程序用什么混淆器,混淆代码?
应该是把用户名和密码作为sql参数,查询到有符合的记录,则验证成功,否则失败。reader.GetString(0) 获取第一列的字符串值。
{
/*
就是就里怎么于登陆窗体的textbox1(用户名)和textbox2(密码)比较是否相等??
*/
if(reader["UserName"].ToString()==textbox1.Text & reader["PassWord"].ToString()==TextBox2.Text)
{
//通过
}
else
{
//非法
}
}
其中UserName,PassWord是楼主表中字段名!!
SqlConnection con = new SqlConnection(@"Data Source=owen\SQL2008;Initial Catalog=mydb;Persist Security Info=True;User ID=sa;password=sa");
SqlCommand com = new SqlCommand(sql, con);
try
{
con.Open();
int i = (int)com.ExecuteScalar();
con.Close();
if (i != 0)
{
MessageBox.Show("登陆成功");
}
else
{
MessageBox.Show("登陆不成功");
}
}
catch (ExecutionEngineException )
{
throw;
}当输入已有用户密码时就没报错.当输入没有的用户和密码是就报错了.
说System.NullReferenceExecption 和{"未将对象引用设置到对象的实例。"}
这样做吧 com = new SqlCommand("select count(*) from StudentClass where username="+text1.text+" and userpwd="+text2.text, con);