各位大虾请看下  这段代码 运行后老是提示
 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();
                }

解决方案 »

  1.   

    SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid + "'", conn);通过你后面代码
    txtuid.Focus();txtuid应该是你的控件名称,
    这样改
    SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid.text + "'", conn);
    123123123 是没有超出int32的范围的 
    convert.Toint32()不会出错 !
      

  2.   

    你的文本框有误,过滤一下前后空格,中间也不能有空格,最好在插放数据库时,验证一下txtuid控件输入的是否为整数
    SqlCommand cmd = new SqlCommand("select count(*) from students where Sno='" +txtuid + "'", conn);
    既然sno是整型的就没必要加引号了,"where sno="+Convert.ToInt32(txtuid)