怎样防止用户名重复注册啊 这是我写的 但一直提示有错误
请高手帮我看看怎么写?(注册页面:用户名-textbox1,密码-textbox2,密码确认--textbox3,邮箱--textbox4)
protected void Button1_Click(object sender, EventArgs e)
{
String sjkxm=TextBox1.Text;
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\news.mdf;Integrated Security=True;User Instance=True");
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from [user] where username=" + sjkxm, conn);
int s=Int32.Parse(cmd.ExecuteScalar().ToString());
if (s==0)
{
Console.WriteLine("用户名重复");
}
if (s==1)
{
register.registeruser(TextBox1.Text, TextBox2.Text, TextBox4.Text,'0');
Label1.Visible = true;
Label1.Text = "恭喜你注册成功";
}
}
"select count(*) from [user] where username=" + sjkxm
è¿æ®µçå符串çæ¼æ¥æé®é¢
æ¹æ"select count(*) from [user] where username=â" + sjkxm+"'"
è¯è¯