sql - Vb.net insert row statement executed twice -
in vb.net application, need backup info 1 table another. here code
con2.open() txt2 = "select * pension empno='" & empno & "' order year" cmd2 = new sqlcommand(txt2, con2) reader2 = cmd2.executereader() while reader2.read yr = reader2("year") totpension = reader2("total") if dr <> yr dcrg = 0 comm = 0 end if tot1 = dcrg + comm + totpension con3.open() txt1 = "insert over1 values('" & empno & "','" & name & "','" & yr & "','" & dcrg & "', '" & comm & "','" & totpension & "','" & tot1 & "')" cmd3 = new sqlcommand(txt1, con3) cmd3.executenonquery() con3.close() end while reader2.close() con2.close()
the problem inserts every record twice, removed order by, same problem continues. using parameterized queries having same problem.
can explain problem in code , how solve it? in advance
multiple things, if have single record of each employee in pension table use if reader2.read
instead of while reader2.read
if problem persists problem executing method twice. question how?
if method. may calling method twiceif event may handling event twice so, check command tag event fired event called there.
<asp:button id="btnsubmit" runat="server" text="submit" onclick="btnsubmit_click"/>
and check event's handled
property
private sub btnsubmit_click(byval sender object, _ byval e starteventargs) handles btnsubmit.click
if defined onclick
attribute must remove handles btnsubmit.click
event.
hope help.
sql vb.net sqlcommand
No comments:
Post a Comment