Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Duplicate Insert ASP.NET

Colour Dalnet:

This is make me crazy this last week. I have read many questions and answer regarding this problem but still can't fixed my problem. I have checked all possible event triggered and can't find any.

I have kondisi.aspx :























btSimpan click event which handled the button is :


Protected Sub btSimpan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btSimpan.Click
Try
If Validasi() Then
If hfMode.Value = "Insert" Then
Insert()
linfoberhasil.Visible = True
linfoberhasil.Text = "Simpan Berhasil"
Else
Update(hfID.Value)
linfoberhasil.Visible = True
linfoberhasil.Text = "Update Berhasil"
End If
End If
Catch ex As Exception
Response.Write("Error button simpan :" & ex.ToString)
End Try
End Sub

This is validation function which checking duplicate item :


Private Function Validasi() As Boolean
Try
clear_label()
If hfMode.Value = "Insert" Then
If tbkondisi.Text.Trim = "" Then
lInfo.Visible = True
lInfo.Text = "Nama kondisi masih kosong"
Return False
End If

sqlstring = "SELECT ID FROM KondisiPengiriman " & _
"WHERE Nama_Kondisi = '" & tbkondisi.Text.Replace("'", "''") & "' " & _
"AND [status] = 1 "
result = SQLExecuteScalar(sqlstring)

If result "" Then
lInfo.Visible = True
lInfo.Text = "Nama kondisi sudah ada"
Return False
End If

End If

If hfMode.Value = "Update" Then
If tbkondisi.Text.Trim = "" Then
lInfo.Visible = True
lInfo.Text = "Nama kondisi masih kosong"
Return False
End If
End If


Return True
Catch ex As Exception
Throw New Exception("Error function Validasi : " & ex.ToString)
End Try
End Function

And here clear_label() function which reset all field :


Private Sub clear_label()
lInfo.Visible = False
lInfo.Text = ""
linfoberhasil.Visible = False
linfoberhasil.Text = ""
End Sub

And finally the insert() function :


Private Sub Insert()
Try
sqlstring = "INSERT INTO KondisiPengiriman " & _
"(Nama_Kondisi, UserName, [status]) VALUES " & _
"('" & tbkondisi.Text.Replace("'", "''") & "', '" & Session("UserId") & "', 1)"
hasil = SQLExecuteNonQuery(sqlstring)

If hasil > 0 Then
load_grid_kondisi()
clear()
End If

Catch ex As Exception
Throw New Exception("Error function insert : " & ex.ToString)
End Try
End Sub

Seems validation() just touched one time and it inserted 2 times, and this is how sql tracing while inserting :


RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.910 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC
Audit Login -- network protocol: LPC
SQL:BatchStarting SELECT ID FROM KondisiPengiriman WHERE Nama_Kondisi = 'tes' AND [status] = 1 .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.910 sa ts11pc TS11PC
SQL:BatchCompleted SELECT ID FROM KondisiPengiriman WHERE Nama_Kondisi = 'tes' AND [status] = 1 .Net SqlClient Data Provider sa 0 2 0 0 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.910 sa ts11pc TS11PC
Audit Logout .Net SqlClient Data Provider sa 0 1782 0 3 15032 55 2017-06-13 10:36:28.910 2017-06-13 10:36:28.913 1 - Non-DAC sa ts11pc TS11PC
RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC
Audit Login -- network protocol: LPC
SQL:BatchStarting INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.913 sa ts11pc TS11PC
SQL:BatchCompleted INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 0 4 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 sa ts11pc TS11PC
Audit Logout .Net SqlClient Data Provider sa 0 1786 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 1 - Non-DAC sa ts11pc TS11PC
RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 0 0 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC
Audit Login -- network protocol: LPC
SQL:BatchStarting INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.913 sa ts11pc TS11PC
SQL:BatchCompleted INSERT INTO KondisiPengiriman (Nama_Kondisi, UserName, [status]) VALUES ('tes', 'LIGITAADMIN', 1) .Net SqlClient Data Provider sa 0 4 0 0 15032 55 2017-06-13 10:36:28.913 2017-06-13 10:36:28.913 sa ts11pc TS11PC
Audit Logout .Net SqlClient Data Provider sa 0 1790 0 3 15032 55 2017-06-13 10:36:28.917 2017-06-13 10:36:28.920 1 - Non-DAC sa ts11pc TS11PC
RPC:Completed exec sp_reset_connection .Net SqlClient Data Provider sa 15 0 0 0 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:36:28.920 0X00000000000000002600730070005F00720065007300650074005F0063006F006E006E0065006300740069006F006E00 sa ts11pc TS11PC
Audit Login -- network protocol: LPC
SQL:BatchStarting SELECT ID, Nama_Kondisi from KondisiPengiriman where [status] = 1 .Net SqlClient Data Provider sa 15032 55 2017-06-13 10:36:28.920 sa ts11pc TS11PC
SQL:BatchCompleted SELECT ID, Nama_Kondisi from KondisiPengiriman where [status] = 1 .Net SqlClient Data Provider sa 0 2 0 0 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:36:28.920 sa ts11pc TS11PC
Audit Logout .Net SqlClient Data Provider sa 0 1792 0 354220 15032 55 2017-06-13 10:36:28.920 2017-06-13 10:42:23.140 1 - Non-DAC sa ts11pc TS11PC

I can't figure out what caused by this, seems the function just run 1 time but the insertion command 2 times. Help and Guide to troubleshoot this really appreaciated. Thank you very much.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Duplicate Insert ASP.NET

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×