string userid = textBox1.Text;
string password = textBox2.Text;
string connection = "server=.;database=mydb;user id=sa;pwd=123";
SqlConnection myconnection = new SqlConnection(connection);
SqlCommand mycommand = myconnection.CreateCommand();
mycommand.CommandText = "select * from 用户信息表 where 用户=''+userid+'' and 密码=''+password+''";
myconnection.Open();
SqlDataReader reader = mycommand.ExecuteReader();
if (reader.HasRows == true)
{
MessageBox.Show("登陆成功", "登陆");
}
else
{ MessageBox.Show("登陆失败", "失败");
}这段程序中,已经没有错误,而我在所连接的数据库的表,设置用户和密码,我在程序的输入框中输入,与数据库表的密码和账号,都报错为登陆失败!请问哪里出现了错误?如何更改
string password = textBox2.Text;
string connection = "server=.;database=mydb;user id=sa;pwd=123";
SqlConnection myconnection = new SqlConnection(connection);
SqlCommand mycommand = myconnection.CreateCommand();
mycommand.CommandText = "select * from 用户信息表 where 用户=''+userid+'' and 密码=''+password+''";
myconnection.Open();
SqlDataReader reader = mycommand.ExecuteReader();
if (reader.HasRows == true)
{
MessageBox.Show("登陆成功", "登陆");
}
else
{ MessageBox.Show("登陆失败", "失败");
}这段程序中,已经没有错误,而我在所连接的数据库的表,设置用户和密码,我在程序的输入框中输入,与数据库表的密码和账号,都报错为登陆失败!请问哪里出现了错误?如何更改
我在程序的输入框中输入,与数据库表的密码和账号.
只能是用户信息表中没有相关的记录。 看看是否有空格。直接把字符串放到sql查询分析器中看看。"select * from 用户信息表 where 用户='" +userid+ "' and 密码='"+password+"'"
sql 里面 ''表示字符串