本文介绍了如何检查数据库中是否已存在电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨通过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(" gmailid" 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(" gmailid"," 密码"); client.Port = 587 ; // Gmail可以在此端口上运行 client.Host = " smtp.gmail.com" ; 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 ' 1'; - 用户名已存在于数据库中 08 09 ELSE 10 11 SELECT ' 0'; - 数据库中不存在用户名 12 13 END
解决方案
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
解决方案
这篇关于如何检查数据库中是否已存在电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!