我在数据库把 账号 设为 wang 密码 设为 d 在登录时提示我输入字符串格式错误;
我在数据库把 账号 设为 1 密码 设为 1 可以正常登录 ;
我在数据库把 账号 设为 王鹏翀 密码 设为 chyjty 在登录时没有响应 ;
这是怎么回事 请路过的大大 讲解一下!!!!
我在数据库把 账号 设为 1 密码 设为 1 可以正常登录 ;
我在数据库把 账号 设为 王鹏翀 密码 设为 chyjty 在登录时没有响应 ;
这是怎么回事 请路过的大大 讲解一下!!!!
if (textBox1.Text == "")
{
MessageBox.Show("请输入用户名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (textBox2.Text == "")
{
MessageBox.Show("请输入密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string str1 = "Data Source=WIN-BKDRIUBDOO8;Initial Catalog=jiayong;Integrated Security=True";
SqlConnection conn = Class1.CyCon(); conn.Open();
SqlCommand cmd = new SqlCommand("select * from [user] where [name]='" + textBox1.Text + "' and power='" + textBox2.Text + "'", conn);
if(Convert.ToInt32(cmd.ExecuteScalar()) > 0)
{
Form2 main = new Form2();
main.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码错误");
}
}
{
MessageBox.Show("请输入用户名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (textBox2.Text == "")
{
MessageBox.Show("请输入密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string str1 = "Data Source=.;Initial Catalog=jiayong;Integrated Security=True";
SqlConnection conn = new SqlConnection(str1); conn.Open();
SqlCommand cmd = new SqlCommand("select name,password from [user] where name='" + textBox1.Text + "' and password ='" + textBox2.Text + "'", conn);
SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows)
{
Form2 main = new Form2();
main.Show();
this.Hide(); }
else
{
MessageBox.Show("非法用户名称或密码!", "出错提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
这句错误应该换为:sqlconnection conn=new sqlconnection(str1)
在关闭form2的语句里加上语句:Application.Exit();
所以
账号 设为 wang 密码 设为 d 在登录时提示我输入字符串格式错误;是因为返回的是wang你将它转换为int型。 账号 设为 1 密码 设为 1 可以正常登录 ;是因为返回的是1大于0。通过!第三个就不知道什么原因。或者像 cy_paul 说的改成 Select count(*) 返回的是行数。也可以。