C#完成检测用户名是否重复事件

2025-03-03 08:05:29
推荐回答(3个)
回答1:

            //conn 是SqlConnection的实例
            SqlCommand cmd = new SqlCommand(string.Format(
                "select count(*) from T_user where userID = {0}",
                textBox1.Text.Trim()), conn);
            if ((int)cmd.ExecuteScalar() > 0)
            {
                //存在
            }

回答2:

userID 为varchar(10) 所以,查询时需要以字符型查询,
"select count(*) from T_user where userID = ‘{0}’",“ ‘{0}’ ”这里要有单引号的。

回答3:

select count(*) from T-user where userId='text'
然后判断返回的和是否大于0