我已经编写代码来删除gridview 中的多条记录,但它只删除gridview 中的一条记录。有人可以帮我解决这个问题。这是我的代码
'This is to Delete multiple records in gridview
Private Sub DeleteMultipleRecords(ByVal idCollection As StringCollection)
'Create sql Connection and Sql Command
Dim cnnOLEDB As New OleDbConnection(strConnectionString)
Dim cmd As New OleDbCommand()
Dim IDs As String = ""
'Create string builder to store
'delete commands separated by ;
For Each id As Integer In idCollection
IDs += id & ","
Next
Try
Dim test As Integer = IDs
Dim sql As String = "DELETE FROM [1BK] WHERE [sampleID] in (" & test & ")"
Dim ANS As Integer
ANS = MsgBox("Are you sure want to delete selected record ?" & vbCrLf & vbCrLf, MsgBoxStyle.YesNo)
If ANS = vbYes Then
cmd.CommandType = CommandType.Text
cmd.CommandText = sql
cmd.Connection = cnnOLEDB
cnnOLEDB.Open()
cmd.ExecuteNonQuery()
End If
ANS = 0
Catch ex As Exception
Dim errorMsg As String = "Error in Deletion"
errorMsg += ex.Message
Throw New Exception(errorMsg)
Finally
cnnOLEDB.Close()
End Try
End Sub