读书人

关于用户名唯一性的有关问题

发布时间: 2012-03-07 09:13:51 作者: rapoo

关于用户名唯一性的问题
SqlConnection MyConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "strConnection "]);
MyConn.Open();
string Sql = "select count(*) from [userinformation] where userName = ' " + strRealName + " ' ";
if
{
Msg.Text= "您所填写的用户名已经存在 ";
return;
}
这里的if后面不知道该写什么,谢谢指教

[解决办法]
用填写的用户去比对数据库内的用户名阿,搜索为空就可以使用,不为空就提示
[解决办法]
SqlConnection MyConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[ "strConnection "]);
MyConn.Open();
string Sql = "select count(*) from [userinformation] where userName = ' " + strRealName + " ' ";
SqlCommand cmd = new SqlCommand(sql,MyConn);
int count = Convert.ToInt32(cmd.ExcuteScare());
MyConn.Close();
if(count> 0)
{
Msg.Text= "您所填写的用户名已经存在 ";
return;
}

[解决办法]
Dim strsql As String
strsql = "select * from users where uname = ' " & Trim(username.Text) & " ' "
Dim strcomm As New OleDbCommand(strsql, conn)
Dim dread As OleDbDataReader
dread = strcomm.ExecuteReader()
If dread.HasRows Then
Label1.Text = "该用户名已经存在 "
Label1.ForeColor = Drawing.Color.Red
dread.Close()
Else

这是VB写的,C#的改下就好了

End If

读书人网 >asp.net

热点推荐