int num = 0;
try
{ string sql = string.Format("select count(*) from login where name={0} and paw={1}", textBox1.Text.Trim(),textBox2.Text.Trim());
SqlCommand com = new SqlCommand(sql, Dbhelp.con);
Dbhelp.con.Open();
num = Convert.ToInt32(com.ExecuteScalar());
MessageBox.Show(sql);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
}
finally
{
Dbhelp.con.Close();
}
if(num==11)
{
MessageBox.Show("Fuck you");
}
输入中文的时候..错误提示 列名小龙无效
try
{ string sql = string.Format("select count(*) from login where name={0} and paw={1}", textBox1.Text.Trim(),textBox2.Text.Trim());
SqlCommand com = new SqlCommand(sql, Dbhelp.con);
Dbhelp.con.Open();
num = Convert.ToInt32(com.ExecuteScalar());
MessageBox.Show(sql);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
}
finally
{
Dbhelp.con.Close();
}
if(num==11)
{
MessageBox.Show("Fuck you");
}
输入中文的时候..错误提示 列名小龙无效
where name='{0}' and paw='{1}'
where name='{0}' and paw='{1}'
很明显 这条 SQL 语句 出了问题,犹如 楼上 说的,因为是字符串 类型,所以必须 给 引号。where name='{0}' and paw='{1}'