Through following code i try to check email already registered(database have or not) or not but it is not working kindly help me
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;
public partial class new_add_donor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mandConnectionString"].ConnectionString);
conn.Open();
string checkdonor = "select count(*) from mydatabase where email='"+TextBox4.Text+"'";
SqlCommand com = new SqlCommand(checkdonor, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("You Email ID is Already Registered Click on Forget Password if you have not Password");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mandConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into mydatabase (dob,name,father,gender,bgroup,distt,tehsil,cv,email,password,repassword,no1,no2,av_not,userdate,user_type) values (@dDate ,@dname ,@dfather ,@dgender ,@dbg ,@ddistt ,@dtehsil ,@dcv ,@demail ,@dpass ,@drepass ,@dno1 ,@dno2 ,@dav ,@ddate ,@duser1)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@ddob", TextBox1.Text);
com.Parameters.AddWithValue("@dname", TextBox2.Text);
com.Parameters.AddWithValue("@dfather", TextBox3.Text);
com.Parameters.AddWithValue("@dgender", DropDownList1.Text);
com.Parameters.AddWithValue("@dbg", DropDownList2.Text);
com.Parameters.AddWithValue("@ddistt", DropDownList3.Text);
com.Parameters.AddWithValue("@dtehsil", DropDownList4.Text);
com.Parameters.AddWithValue("@dcv", DropDownList5.Text);
com.Parameters.AddWithValue("@demail", TextBox4.Text);
com.Parameters.AddWithValue("@dpass", TextBox5.Text);
com.Parameters.AddWithValue("@drepass", TextBox6.Text);
com.Parameters.AddWithValue("@dno1", TextBox7.Text);
com.Parameters.AddWithValue("@dno2", TextBox8.Text);
com.Parameters.AddWithValue("@dav", DropDownList6.Text);
com.Parameters.AddWithValue("@ddate", TextBox9.Text);
com.Parameters.AddWithValue("@duser1", TextBox10.Text);
com.ExecuteNonQuery();
Response.Write("<script>alert('Dairy has been Saved Successfully.');</script>");
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
}
}