如何检查数据库中是否已存在电子邮件 [英] how to check email is already there in database or not

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

问题描述


通过gmail忘记密码的编码工作正常,我的问题是如何检查数据库中是否存在密码,如果不存在,请先注册.如何为此编写代码
编码

 使用(SqlConnection con =  SqlConnection(_constr))
        {
            字符串查询= "  + txtemail.Text +  '";
            SqlCommand cmd =  SqlCommand(query,con);
           
            SqlDataAdapter da =  SqlDataAdapter(cmd);
            DataSet ds =  DataSet();
            da.Fill(ds);
              int  rowcount = ds.Tables [ 0 ].Rows.Count;
             如果(行计数>   0 )
             {
                 email = ds.Tables [ 0 ].行[ 0 ] [ 电子邮件"].ToString();
                 密码= ds.Tables [ 0 ].行[ 0 ] [ 密码"].ToString();

                 MailMessage邮件=  MailMessage();
                 mail.From =  MailAddress("  span>);
                 mail.To.Add(电子邮件);
                 mail.Subject = " ;
                 mail.Body = "  +  "  + txtemail.Text.ToString()+ "  + "  +密码;
                 mail.Priority = System.Net.Mail.MailPriority.High;
                 SmtpClient client =  SmtpClient();
                 client.Credentials =  System.Net.NetworkCredential("  密码");
                 client.Port =  587 ; //  Gmail可以在此端口上运行
                 client.Host = " ;
                 client.EnableSsl =  true ; //  Gmail可在服务器安全层上运行
                 //  lbl6.Text =密码已成功发送到" +电子邮件; 
                 client.Send(邮件);
            }
        } 



我的数据库编码是

  01  创建 >过程 CheckUserName( @ User_Name   VARCHAR ( 50 ))
 02   AS 
 03   BEGIN 
 04 
 05   IF   EXISTS (选择 *  FROM  User_Table 位置 [User_Name] =  @ User_Name )
 06 
 07   SELECT  ' - 用户名已存在于数据库中
 08 
 09   ELSE 
 10 
 11   SELECT  ' - 数据库中不存在用户名
 12 
 13   END  

解决方案

在数据库上触发查询,

从登录位置选择COUNT(EmailId)EmailId = @ EmailId

如果返回的计数大于零,则表示数据库中存在电子邮件ID.


hi
coding for forget password through gmail is working fine my question is how to check wheather email id is there in database or not if its not there execute please register first. how write coding for this
coding

using (SqlConnection con = new SqlConnection(_constr))
        {
            string query = "select Password,email from login where email='" + txtemail.Text + "'";
            SqlCommand cmd = new SqlCommand(query, con);
           
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
             int  rowcount = ds.Tables[0].Rows.Count;
             if (rowcount > 0)
             {
                 email = ds.Tables[0].Rows[0]["email"].ToString();
                 password = ds.Tables[0].Rows[0]["password"].ToString();

                 MailMessage mail = new MailMessage();
                 mail.From = new MailAddress("gmailid");
                 mail.To.Add(email);
                 mail.Subject = "Reg. Password ";
                 mail.Body = " Your Password for the user" + " " + txtemail.Text.ToString() + " " + " is " + password;
                 mail.Priority = System.Net.Mail.MailPriority.High;
                 SmtpClient client = new SmtpClient();
                 client.Credentials = new System.Net.NetworkCredential("gmailid", "password");
                 client.Port = 587; // Gmail works on this port
                 client.Host = "smtp.gmail.com";
                 client.EnableSsl = true; //Gmail works on Server Secured Layer
                 //lbl6.Text = " The password has successfully sent to " + email;
                 client.Send(mail);      
            }
        }



my database coding is

01	CREATE PROCEDURE CheckUserName(  @User_Name VARCHAR(50) )
02	AS
03	BEGIN
04	 
05	  IF EXISTS (SELECT * FROM User_Table WHERE  [User_Name] = @User_Name ) 
06	 
07	  SELECT '1'; --user name already exist in database
08	 
09	  ELSE
10	 
11	  SELECT '0'; --user name does not exist in database
12	 
13	END

解决方案

Fire the query on the database as

SELECT COUNT(EmailId) FROM login WHERE EmailId=@EmailId

If the count returned is more then zero, this means the email id exists in the database.


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

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