using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Text; using System.Net; using System.Net.Mail; namespace logindemo { public partial class Register : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnRegister_Click(object sender, EventArgs e) { string connetionString = "Data Source=INFND-DTP-0493;Initial Catalog=Test_DB;User ID=#####;Password=#####"; SqlConnection conn = new SqlConnection(connetionString); conn.Open(); string commText = "select * from login where user_name='"+txtUserName.Text.Trim()+"' or email_id= '" + txtEmailId.Text.Trim() +"' or phone_no=" + Convert.ToDouble(txtPhoneNo.Text) ; SqlCommand cmd = new SqlCommand(commText, conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { Label1.Text = "Duplicte of Data"; } else { conn.Close(); MailMessage msg; string commText1 = "insert into login(User_Name,Password,Address,City,State,PIN,Phone_no,Email_id,Created_By,Created_on) values('" + txtUserName.Text + "','" + txtPassword.Text + "','" + txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + Convert.ToDouble(txtPin.Text) + "','" + Convert.ToDouble(txtPhoneNo.Text) + "','" + txtEmailId.Text + "','" + "Alok" + "','" + DateTime.Now + "')"; SqlCommand cmd1 = new SqlCommand(commText1, conn); conn.Open(); int no = cmd1.ExecuteNonQuery(); conn.Close(); if(no>0) { Label1.Text= "User registration sucessfully"; System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(txtEmailId.Text.Trim()); mail.From = new MailAddress("alokparhi06@gmail.com"); mail.Subject = "Regarding: Registration conformation"; mail.Body = "Hi"+txtUserName.Text.Trim()+", You have registered successfully..."; mail.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("alokparhi06@gmail.com", "xyz"); client.Port = 587; client.Host = "smtp.gmail.com"; client.EnableSsl = true; try { client.Send(mail); } catch { Label1.Text="There is some problem while sending Message... "; } } else { Label1.Text="Error"; } } } } }
catch(exception ex){throw ex;//Label1.Text="There is some problem while sending Message... "; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)