In this Post Check Already Email In this Example use in cname,city,emailaddress Insert table Data Value.
Important Namespaces used -------------------------- using System.Data; using System.Data.SqlClient; -------------------------- Register Button Click Event Coding ------------------------------------- if(checkemail()==true) { Label3.Text = "Your Email Already Registered with Us"; TextBox3.BackColor = System.Drawing.Color.PaleGreen; } else { String query = "insert into registrationdetail(cname,city,emailaddress) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')"; String mycon = "Data Source=HP-PC\\SQLEXPRESS; Initial Catalog=RegisteredData1; Integrated Security=true"; SqlConnection con = new SqlConnection(mycon); con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; cmd.ExecuteNonQuery(); Label3.Text = "Registration Has Been Saved Successfully"; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; } ----------------------------- User Defined Method ----------------------------- private Boolean checkemail() { Boolean emailavailable = false; String mycon = "Data Source=HP-PC\\SQLEXPRESS; Initial Catalog=RegisteredData1; Integrated Security=True"; String myquery = "Select * from registrationdetail where emailaddress='" + TextBox3.Text+"'"; SqlConnection con = new SqlConnection(mycon); SqlCommand cmd = new SqlCommand(); cmd.CommandText = myquery; cmd.Connection = con; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { emailavailable = true; } con.Close(); return emailavailable; }