There are 2 textbox on web Page say First Name, Last Name, etc.
And a Button called Insert Records.
On Click of Insert Button, records get inserted. After inserting the records, If you refresh the page, it will again insert records.
How can you prevent it?
ArshadPosted Oct 29, 2008, 4:11 PM
if(ViewState["Khan"]==null)
{
//your code for Adding the Data in your database
//after that just assign the value to the viewstate, some thing like that
ViewState["Khan"].ToString()=="Done"
}
I hope it should work, please check it n let me know.
Thanks
zafar jaffaryPosted Oct 27, 2008, 10:40 AM
Hello
Did your problem solve already? I have the same problem. I have a button on my asp.net application it should insert new record if no record exist in the database otherwise update the record.
Can you help me out? if i give you my code?
Thanks
Kirtan PatelPosted Oct 10, 2008, 7:20 PM
See Following Code Written by me
protected void btnInsert_Click(object sender, EventArgs e)
{
con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
Response.Write("Connection Success");
comm = new SqlCommand();
comm.Connection = con;
comm.CommandText = "INSERT INTO users VALUES('" + txtUsername.Text + "','" + txtPassword.Text + "')";
comm.ExecuteNonQuery();
con.Close();
Response.Redirect("~/default.aspx");
showdata();
}
Regards,
Niradhip ChakrabortyPosted Oct 10, 2008, 5:42 PM
Vijaya KadiyalaPosted Oct 10, 2008, 12:43 PM
Hi,
You need to place Business Unique keys on the table columns to avoid this.
Thanks -- Vj
http
://dotnetvj.blogspot.comhttp
://oravj.blogspot.com