//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)
{
//存在
}
userID 为varchar(10) 所以,查询时需要以字符型查询,
"select count(*) from T_user where userID = ‘{0}’",“ ‘{0}’ ”这里要有单引号的。
select count(*) from T-user where userId='text'
然后判断返回的和是否大于0