Click here to Skip to main content
15,887,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
C#
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
SQL
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
Posted
Updated 29-Apr-12 7:21am
v3
Comments
bbirajdar 29-Apr-12 10:42am    
Reason for my vote of 1
You need to post the database structure so that somebody can suggest you

1 solution

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.
 
Share this answer
 
Comments
Parveen Rathi 1-May-12 5:19am    
Yes this is the write answer
bbirajdar 2-May-12 4:59am    
Thank you. But somebody downvoted it , without specifying a reason

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900