下午本来想适应一下登录验证的设计,结果错误接踵而来.纠正了大半天,还是没有搞定.本以为很快就可以搞定的...结果一直拖到晚上.
先是在判断用户名或密码为空时进行了处理,原以为
if (!textBox1.Text) 或者
if (textBox1.Text==null) 就可以搞定.结果编译老是报错.......想了半天,于是改为
if (textBox1.Text="") 这样终于可以搞定了
于是我想,难道.net开发平台不支持前面两种情况吗?怀疑ing.................
接着就是报了一个非常头痛的错误.系统老是报出这样的一种错误
真是让我很头疼.也看不懂上面究竟写的是什么.
但我大体明白问题应该出现在以下几行代码:
this.sqlConnection1.ConnectionString = "workstation id=\"DELL-FLA\";packet size=4096;integrated security=SSPI;data source=\"" +
"dell-fla\";persist security info=False;initial catalog=Book";
这是连接数据库.
string loginstr = "SELECT UserPsw FROM User" + "WHERE (UserName = '"+ this.textBox1.Text +"')";
SqlCommand mycom = new SqlCommand(loginstr,this.sqlConnection1);
try
{

真是让我很头疼.也看不懂上面究竟写的是什么.
但我大体明白问题应该出现在以下几行代码:
this.sqlConnection1.ConnectionString = "workstation id=\"DELL-FLA\";packet size=4096;integrated security=SSPI;data source=\"" +
"dell-fla\";persist security info=False;initial catalog=Book";
这是连接数据库.
string loginstr = "SELECT UserPsw FROM User" + "WHERE (UserName = '"+ this.textBox1.Text +"')";
SqlCommand mycom = new SqlCommand(loginstr,this.sqlConnection1);
try
{
this.sqlConnection1.Open();
SqlDataReader loginreader;
loginreader = mycom.ExecuteReader();
if (loginreader.Read())
{
this.Visible=false;
Form1 form = new Form1();
form.ShowDialog();
this.Visible=true;
}
else
{
MessageBox.Show("请输入正确用户名和密码!!");
return;
}
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
this.sqlConnection1.Close();
这是按扭事件处理,真搞不懂到底出错在哪
不管了,还是早点睡吧,明天再想了
loginreader = mycom.ExecuteReader();
if (loginreader.Read())
{
this.Visible=false;
Form1 form = new Form1();
form.ShowDialog();
this.Visible=true;
}
else
{
MessageBox.Show("请输入正确用户名和密码!!");
return;
}
}
catch(Exception ee)
{
MessageBox.Show(ee.ToString());
}
this.sqlConnection1.Close();
这是按扭事件处理,真搞不懂到底出错在哪
不管了,还是早点睡吧,明天再想了