如何知道电子邮件地址在数据库中是否可用 [英] How to know the email address is available in the database

查看:122
本文介绍了如何知道电子邮件地址在数据库中是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


注册时如何知道数据库中的电子邮件地址可用


谢谢

解决方案

运行查询,选择电子邮件与输入电子邮件相同的行或COUNT.

例如

 SqlCommand命令=  SqlCommand(" 中选择COUNT(*),myConnection);
command.Parameters.Add(" ,SqlDbType.VarChar).Value = inputEmail;
 int  count =( int )命令.ExecuteScalar();
如果(计数!=  0 )
{
    // 电子邮件已被使用
} 


在注册过程中,您可以验证数据库并检查是否存在电子邮件ID.您还可以在后台使用AJAX或JQuery进行帮助.


如果我正确理解了您的问题,那是一个相当广泛的问题.它至少应包括以下步骤:

  • 在进行新注册时为包含电子邮件地址的现有帐户创建一个表
  • :

    • 创建连接
    • 创建命令
    • 定义一条选择语句,检查电子邮件是否存在.诸如此类:
    •  帐户选择 count(*) 其中电子邮件=  @电子邮件 


    • 检查结果是否为0.如果是,则表明该电子邮件地址已被注册
    • 完成注册
    • 将新电子邮件地址添加到新帐户行中(请记住可能的情况) -数据库中的敏感性)
    • 提交更改

  • 让用户知道操作是否成功


为此所需的一些类(如果使用Sql Server,则为该类):

Run a query selecting the rows or COUNT where the email is the same as the input email.

E.g.

SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM users u WHERE u.email = :EMAIL", myConnection);
command.Parameters.Add(":EMAIL", SqlDbType.VarChar).Value = inputEmail;
int count = (int) command.ExecuteScalar();
if(count != 0)
{
    // The email is already used
}


During the registration, you can validate the database and check if the email id is exist of not. You can also take help of AJAX or JQuery to do it behind the scene.


If I understood your question correctly, it''s a quite broad question. It would include at least the following steps:

  • create a table for existing accounts containing the email addresses
  • when a new registration is going on:

    • create a connection
    • create a command
    • define a select statement checking for the email existence. Something like:
    • select count(*) from account where email = @email


    • check if the result is 0. If it is, the email address is already registered
    • complete the registration
    • add the new email address to new account row (remember possible case-sensitivity in the database)
    • commit the changes

  • let the user know if the operation was successful


Some of the classes needed for this (for Sql Server if that is used):


这篇关于如何知道电子邮件地址在数据库中是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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