Private Sub btn_trans_Click(sender As Object,e As EventArgs) Handles btn_trans.Click Dim mytransaction As OleDb.OleDbTransaction myconnection2.Open() mytransaction = myconnection2.BeginTransaction Try For i As Integer = 0 To grd_order.RowCount - 1 Dim orderid As String = grd_order(0,i).Value Dim orderdate As String = grd_order(1,i).Value Dim customerid As String = grd_order(2,i).Value Dim staffid As String = grd_order(3,i).Value Dim mysql As String = "INSERT INTO TBL_ORDER_A167640 VALUES ('" & orderid & "','" & orderdate & "','" & customerid & "','" & staffid & "')" Dim mywriter As New OleDb.OleDbCommand(mysql,myconnection2,mytransaction) mywriter.ExecuteNonQuery() Next mytransaction.Commit() myconnection2.Close() Beep() MsgBox("Transaction successful!") refresh_grid() grd_order.Rows.Clear() Catch ex As Exception Beep() MsgBox("Problem with transaction:" & vbCrLf & vbCrLf & ex.Message) mytransaction.Rollback() myconnection2.Close() refresh_grid() End Try End Sub
此代码有什么问题?我无法将新数据插入ms-access数据库,因为它说我将创建重复数据。我该怎么办