开发者

Asp.net data insert into sqlserver

I've a webpage with form and a button.Onclicking the button it inserts/updates data into sql server.The button is disabled once it clicked .Its was working fine when testing .But in production sometimes it inserts DATA twice.I'm not sure why its doing like that.Please let me know whats going wrong??

开发者_开发技巧

Regards, Ravi


someone could easily just hit F5 while your form is submitting. Even worse - if you are not redirecting after the submit - someone can hit F5 after your form is done submitting.

One way to work around that is to add a guid token to your form (new generated every time form loads). The on POST you store that token in the table you insert stuff into. Before that you obviously check your table is posted token already exists in there and if it does - update you records instead of inserting the new one, or simply redirect to the result page.


Ravi, You may be calling your routine twice. Have you looked into that?

Use this:

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=asp.net+inserts+data+twice

No offense intended by the search. I only present it because so many seem to have experienced this that you should get a good answer, after examining your code carefully.

You need to put the insert code up or tell how your doing it if you want a more specific answer.


Try to use Post-Redirect-Get pattern, that solves problem with inserting some data twice. If browser sends post request to the server for update/inserting/modify actions and then returns response after these actions, hit on f5 button sends your previous request to the server again and actions execute again.

Also it can be result of double click on the button that sends request to insert data. Maybe you need to check if there is already the data that need to be inserted.

Hope you will find the answer to your question.

Best regards, Dima.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜