I have a GridViewwith rows containing .net checkboxcontrol. User would check the rows and upon clicking the button it would insert the checked rows in the table GeneratedInvoiceBatches
VB Code:
Protected Sub btnGenerate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim grItem As DataGridItem
Dim i As Integer = 0
For Each grItem In grdTransactions.Items
If grItem.ItemType = ListItemType.AlternatingItem Or grItem.ItemType = ListItemType.Item Then
If CType(grItem.Cells(0).FindControl("chkSelect"), CheckBox).Checked = True Then
Utilities.InsertUnsettledBatchesForInvoice(grItem.Cells(5).Text.Trim, grItem.Cells(7).Text.Trim, grItem.Cells(11).Text.Trim)
i = i + 1
End If
End If
Next
If i = 0 Then
Response.Write("<script> alert('No selected record(s) to process!');</script>")
Else
Response.Write("<script> alert('Operation Successful!');</script>")
BindDataGrid()
End If
End Sub
Stored Procedure:
Create proc [dbo].[spInsertUnsettledBatchesForInvoice]
@TerminalID varchar(8),
@BatchNumber int,
@SettledAmount money
as
insert into GeneratedInvoiceBatches (GenerationDate,TerminalID,BatchNumber,SettledAmount,isPayment,isHSBCFile,paymentdate)
values
(GetDate(),@TerminalID,@BatchNumber,@SettledAmount,1,1,getdate())
Problem is sometimes it inserts duplicate rows say once in three months. Can somebody identify the issue? Is it something to do with the checkbox control? How can I avoid this duplication?
Aucun commentaire:
Enregistrer un commentaire