how to avoid duplicate insert of gridview data using asp.net c# on button click for example
SqlConnection zcon = new SqlConnection(ConfigurationManager.ConnectionStrings["invConnectionString"].ConnectionString);
zcon.Open();
foreach (GridViewRow gvr in GridView3.Rows)
{
string data1 = ((Label)gvr.FindControl("L1")).Text;
string data2 = ((Label)gvr.FindControl("L2")).Text;
string data3 = ((Label)gvr.FindControl("L3")).Text;
SqlCommand ck = new SqlCommand("Insert into Store(Format,Name,Qty)values(@Format,@Name,@Qty)", zcon);
ck.Parameters.Add(new SqlParameter("@Format", data1));
ck.Parameters.Add(new SqlParameter("@Name", data2));
ck.Parameters.Add(new SqlParameter("@Card_Qty", data3));
ck.ExecuteNonQuery();
}
My gridview has only this data
sometimes it goes two times to sql database table or more how to avoid such duplicates..