while inserting record in sql server database. every time inserting 2 records, i think event firing two times. how to stop inserting records twice in ado.net.
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
CompanyName = txtCompany.Text.Trim();
InsertData();
}
catch (Exception)
{
throw;
}
}
private void InsertData()
{
if (Page.IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kernelCS"].ConnectionString);
SqlCommand cmd = new SqlCommand(@"INSERT INTO [tbl_Leads]([CompanyName])VALUES(@CompanyName)", con);
cmd.Parameters.AddWithValue("@CompanyName", txtCompany.Text.ToString());
con.Open();
cmd.ExecuteNonQuery();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
...
}
}
if (Page.IsPostBack)in your private method?