各位大虾请看下 这段代码 运行后老是提示
SqlConnection conn = new SqlConnection("server=PENG\\SQLEXPRESS;database=students_info ;integrated security=true");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid + "'", conn);
string i = cmd.ExecuteScalar().ToString();
//在将 varchar 值 'System.Windows.Forms.TextBox, Text: 123123123' 转换成数据类型 int 时失败。
cmd.Connection.Close();
if (i =="")
{
MessageBox.Show("您输入的用户名或密码不正确!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtuid.Focus();
}
else
{
choose();
}
SqlConnection conn = new SqlConnection("server=PENG\\SQLEXPRESS;database=students_info ;integrated security=true");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid + "'", conn);
string i = cmd.ExecuteScalar().ToString();
//在将 varchar 值 'System.Windows.Forms.TextBox, Text: 123123123' 转换成数据类型 int 时失败。
cmd.Connection.Close();
if (i =="")
{
MessageBox.Show("您输入的用户名或密码不正确!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtuid.Focus();
}
else
{
choose();
}
txtuid.Focus();txtuid应该是你的控件名称,
这样改
SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid.text + "'", conn);
123123123 是没有超出int32的范围的
convert.Toint32()不会出错 !
SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid + "'", conn);
既然sno是整型的就没必要加引号了,"where sno="+Convert.ToInt32(txtuid)