请教: 这样的myCmd.ExecuteNonQuery()竟返回-1

我有一数据库restaurant,其中有一表admin,表中两三字段:adminName(主键),adminPwd,empID(外键)

有两条数值

adminName          adminPwd      empID

admin1001            admin1001    1001

admin1002            admin1002     1002

我是通过表进行验证登录,却不成功,源码如下:

 

        private void button1_Click(object sender, EventArgs e)
        {
           //创建数据库连接
            SqlConnection conn = Sql.createCon();
            conn.Open();
            //验证密码
            if (this.textBox1.Text =="")
                MessageBox.Show("密码不能为空");
            //用数据库验证
            string sql = "select count(*) from admin where adminName='";
            sql += this.comboBox1.SelectedItem.ToString();
            sql += "' and adminPwd='";
            sql +=this.textBox1.Text.ToString()+"'";
            SqlCommand myCmd = new SqlCommand(sql,conn);
            int count = myCmd.ExecuteNonQuery();
            if (count>0)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("你的密码不正确!");
            }
            conn.Close();
        } 

 

用户名用combobox选中,密码是用textbox接收,我用断点查过sql的值已经是select count(*) from admin where adminName='admin1001' and adminPwd='admin1001'   并在查询分析器中运行中得到影响行数为1了,为什么在winForm里面就不行了,请教高手!谢谢!

你可能感兴趣的:(C#.NET)