怎么判断用户名字在数据库中存在~~~ 一个注册功能怎么能判断出注册的名字在数据库中存在!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用SQL语句从数据库中查找当前当前名城的记录是否存在。也可以对记录进行缓存,然后建立一个合理的数据结构,在内存中处理。用然后用ajax异步调用此方法。 SELECT COUNT(0) FROM 你的用户表 WHERE 用户名 = 用户输入的字串.replace(''','''')然后判断是否 dr.Read()google一下吧,大神会告诉你天上的星星有很多很多. select count(id) from table where name = @nameif (return value == 0){ //todo:name doesn't exist}else{ // already be used name} select count(*) from UerInfo wherename="name"获得返回的结果,是0就是不存在,是1就存在 注册是 写上一个sql查询 判断下 string strname=txtname.text.trim();string sqlstr=“select count(id) from table where name=‘“+strname+”’”;if(sqlstr==true){ 就是有了 }else{ 没有可以注册} select count(*) from tablewhere username='注册的名字'如果返回0,则数据库中不存在注册的名字;如果返回1,则数据库中已存在要注册的名字。 你可以select 判断一下时候有结果返回 if not exists(SELECT * FROM 用户表 WHERE UserName=@UserName)INSERT INTO 用户表 VALUES()@UserName就是传入的注册名 ajax异步获取数据,查询用户数据 <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function CheckUserName() { var us=document.getElementById("txtname").value; if(us!="") { createXMLHttpRequest(); var url= "RegistValidate.ashx?username="+escape(document.getElementById("txtname").value); xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=ShowResult; xmlHttp.send(null); } } function ShowResult() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var s; s=xmlHttp.responseText; alert(s); } } } </script>string sql = "select count(*) from [user] where username = '"+username.Text+"'"; int count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, sql)); if (count > 0) flag = true;'存在 else flag = false;'不存在 这个是以前做的 还可以http://blog.csdn.net/liaoyukun111/archive/2009/09/24/4589366.aspx 异步检查用户名是否存在http://topic.csdn.net/u/20100122/17/2fd20620-322b-4910-ad35-3b3173b651a9.html检查的关键是执行SQL查询语句,楼上都贴了 可以用ajax异步获取数据,查询用户数据 ,也可以直接到数据库里去查 输入的用户名作为数据库查询 的条件这样来写SQL语句,能查出来就存在,不能查出来就不存在 if not exists( select * from User where UserName = '新输入的用户' )return trueelsereturn false 这样的问题也值40啊。没有哪个做数据库关联程序的会不知道答案的说,无论PHP,JAVA,VB..... 存储过程中:if not exists( select id from User where UserName = '新输入的用户''insert intoelse'啥也不做 /// <summary> /// Does this user exist? /// </summary> /// <param name="name">user name(string)</param> /// <returns>return bool value</returns> public static bool IsExist(string name) { strSQL = "Select companyID from company Where Name='" + name + "'"; try { ExecuteSqlValue(strSQL); return true; } catch { return false; } } 用membership吧,很方便的,这个类有一个方法可以检测用户的存在 webform中使用mschart控件 vs 2008 如何做出手机端的WAP页面? 网上找了一个存储过程分页 我不知道怎么用 求助 |zyciis| 如何在aspx文件中写及时代码输出菜单事,谢谢 急 在线的朋友看一下,这个xml是怎么生成的 关于页面间传递参数的问题 送点小分,顺便问个问题:web和数据库放在不同的服务器上 没有人会吗?——调用动态加载的用户控件的属性方法???? 请各位大侠提点建议:怎样学习在ASP.NET开发中应用XML技术??? .net 项目生成的一个问题,未能找到源文件 DropDownList1 取值问题 代码填充
也可以对记录进行缓存,然后建立一个合理的数据结构,在内存中处理。
用然后用ajax异步调用此方法。
select count(id) from table where name = @name
if (return value == 0)
{
//todo:name doesn't exist
}
else
{
// already be used name
}
获得返回的结果,是0就是不存在,是1就存在
string sqlstr=“select count(id) from table where name=‘“+strname+”’”;if(sqlstr==true)
{
就是有了
}
else
{
没有可以注册
}
where username='注册的名字'
如果返回0,则数据库中不存在注册的名字;
如果返回1,则数据库中已存在要注册的名字。
INSERT INTO 用户表 VALUES()@UserName就是传入的注册名
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}
function CheckUserName()
{
var us=document.getElementById("txtname").value;
if(us!="")
{
createXMLHttpRequest();
var url= "RegistValidate.ashx?username="+escape(document.getElementById("txtname").value);
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
}
}
function ShowResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var s;
s=xmlHttp.responseText;
alert(s);
}
}
}
</script>
string sql = "select count(*) from [user] where username = '"+username.Text+"'";
int count = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.Conn, CommandType.Text, sql));
if (count > 0)
flag = true;'存在
else
flag = false;'不存在
http://blog.csdn.net/liaoyukun111/archive/2009/09/24/4589366.aspx
检查的关键是执行SQL查询语句,楼上都贴了
return true
else
return false
'啥也不做
/// Does this user exist?
/// </summary>
/// <param name="name">user name(string)</param>
/// <returns>return bool value</returns>
public static bool IsExist(string name)
{
strSQL = "Select companyID from company Where Name='"
+ name + "'"; try
{
ExecuteSqlValue(strSQL);
return true;
}
catch
{
return false;
} }