Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 15213 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > how to check email is already there in database or not ...
Reddysankark@Yahoo.Com

how to check email is already there in database or not

Replies: 1 | Posted by: Reddysankark@Yahoo.Com on 4/29/2012 | Category: ASP.NET Forums | Views: 850 | Status: [Member] | Points: 10  


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:

CREATE PROCEDURE CheckUserName( @email VARCHAR(50) )
AS
BEGIN

IF EXISTS (SELECT COUNT(email) FROM email WHERE [email] = @email )

SELECT '1'; --user name already exist in database

ELSE

SELECT '0'; --user name does not exist in database

END

sankarreddy


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Johnbhatt
Johnbhatt  
Posted on: 7/14/2012 9:03:44 AM
Level: Starter | Status: [Member] | Points: 25

So, you have a good code, what is your problem. Check Stored Procedure before Sending a mail.
ie.
First Check that if email id exists or not which you have done in below step.
int rowcount = ds.Tables[0].Rows.Count;

if (rowcount > 0)

Now just place an Else block and print a message, "This Email ID is not associated with us, Register here."



John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Reddysankark@Yahoo.Com, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/18/2013 5:29:36 PM