我正在尝试将datagridview的所有行插入到数据库表中。下面是我的代码和错误消息快照。可以告诉我哪里出错了。 我尝试将for循环放在代码的不同部分,一次将行成功插入表中,但仍然出现错误消息。
Private Sub addnewclasses()
Dim open As String = db.OpenDB
If open <> "OK" Then
MessageBox.Show("Error openining the database check the connection path to your database:", "POS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
For i As Integer = 0 To DGV_Class.Rows.Count - 1
Dim AirlineCode As String = DGV_Airline.Rows(0).Cells(0).Value
Dim ClassCode As String = DGV_Class.Rows(i).Cells(0).Value
Dim ClassDesc As String = DGV_Class.Rows(i).Cells(1).Value
Dim ClassSort As Integer = DGV_Class.Rows(i).Cells(2).Value
Dim ClassBook As Boolean = DGV_Class.Rows(i).Cells(3).Value
'========================================================================
airline.setairlinecode(AirlineCode)
airline.setClassCode(ClassCode)
airline.setClassDesc(ClassDesc)
airline.setClassSort(ClassSort)
airline.setClassBooking(ClassBook)
'========================================================================
Next
Try
If Not airline.insert_class_master(db, True) Then
MessageBox.Show("Error occurred while adding new airline to the system make sure the information your provided is correct!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
MessageBox.Show("New airline has been added to the system successfully", "system Updated successfully", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Public Function insert_class_master(ByVal dbaccesscl As databaselogic, ByVal save As Boolean) As Boolean
Try
Dim SQL As String = "insert into Tbl_Class_Master ( " & _
"Airline_Code, " & _
"Class_Code, " & _
"Class_Description, " & _
"Class_Sorting, " & _
"Class_Booking) values " & _
"(@0,@1,@2,@3,@4)"
dbaccesscl.ExecuteSQL(SQL, Me.AirlineCode, Me.ClassCode, Me.ClassDesc, Me.Classsort, Me.Classbooking)
If save Then
dbaccesscl.Commit()
End If
Return True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "error from inserting")
dbaccesscl.Rollback()
Return False
End Try
End Function
参数化查询&#39;(@ 0 nvarchar(2),@ 1 nvarchar(4000),@ 2 nvarchar(4000),@ 3 int,@ 4位需要参数&#39; @ 1&#39; ,没有提供。