C#SQL数据查询问题

来源:百度知道 编辑:UC知道 时间:2024/09/25 05:55:12
string sql = string.Format("select count(*) from Table1_userinfo where userid='{1}' and password='{1}'", loginId, loginPwd);
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
int count = (int)command.ExecuteScalar();
if (count < 1)
{
MessageBox.Show("用户名或密码不存在!");
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source);
return false;
}
finally

SqlConnection connection = new SqlConnection(SQL_str);
try
{

connection.Open();
string cmdText = "select count(*) from login where loginname='" + textBox1.Text + "' and loginpassword='" + textBox2.Text + "'";
SqlCommand command = new SqlCommand(cmdText, connection);
int count = Convert.ToInt32(command.ExecuteScalar());
if (count > 0)
{
Form2 form2 = new Form2();
form2.Show();
}
else
{
label6.Text = "用户名或密码输入错误,请重新输入。";
textBox1.Clear();
textBox2.Clear();
}

}
catch (Exception ex)