使用C#在ASP.NET中使用数据库检查用户名的可用性 [英] check availability of username with database in asp.net using c#

查看:102
本文介绍了使用C#在ASP.NET中使用数据库检查用户名的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个关于用户名检查可用性的小问题.


当我输入文本时,我想检查我的数据库.它不在那里意味着它将像此名称一样显示,否则它将显示未分配给注册人的错误.

Hi Guys,


I have a small problem about username check availability.


when i entered text i want to check my database .its not there means it ll show like this name available, otherwise it ll show error not alloved to signup.

推荐答案

尝试以这种方式找出

try to find out in this way

 if exists(select * from CandidateDetails where Email = ''abc@gmail.com'')
begin
print ''Exists''
end
else
begin
print ''Not Exists''
end

// else 
//In DataBase
 
  declare @result int
  select @result= Count(*) from table where Email =''abc@gmail.com''
  select @result
// In C# CodeBehind  return that value from database  and retrieve it in asp.net with 
           int Result = Convert.toInt(ObjCommand.Excecutescalar);
            if (Result>0)
              {
                  // Email Matches
              }
           else 
              {
                  //No Matching Email Found
              }


您刚刚使用了此命令
从表中选择用户名,其中username = @ username;
和二手的数据读取器.
如果datareader read()则它存在,否则它是可用的.
You just used this command
Select username from table where username=@username;
and used datareader.
if datareader read() then it exists otherwise it is available.


这篇关于使用C#在ASP.NET中使用数据库检查用户名的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆