2015-04-23 66 views
0

我有一個GridView,其中包含.net checkbox控件的行。用戶將檢查行和在點擊該按鈕,將在表insertcheckedGeneratedInvoiceBatchesDB中的重複插入

VB代碼:

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 

存儲過程:

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()) 

問題是有時它插入重複行在三個月內說一次。有人可以確定這個問題嗎?這與複選框控件有關嗎?我怎樣才能避免這種重複?

+0

哪個值確定記錄是重複的? –

+1

如果不是在任何點擊重複..比通過點擊意外兩次..在dgv相同的行,你可以檢查是否存在分貝警告.. – CristiC777

+0

是似乎我必須使用NOT EXISTS用子查詢來檢查是否有重複 – Nuke

回答

0

我的猜測是該按鈕被連續點擊兩次。調用數據庫插入後,您可以取消選中If-Then右側的框嗎?這樣,第二次點擊將找不到任何複選框。