以下是我的代码:
For l As Integer = 0 To DataGridView1.Rows.Count Step 1
Dim sjdy As String = "insert into lsb(业务编码,开票金额,收款金额) VALUES ('" + DataGridView1.Rows(l).Cells(0).Value.ToString() + "','" + DataGridView1.Rows(l).Cells(3).Value.ToString() + "','" + DataGridView1.Rows(l).Cells(5).Value.ToString() + "') "
Dim sjdyCommand As OleDbCommand = New OleDbCommand(sjdy, myConn)
sjdyCommand.ExecuteNonQuery()
Next
提示以下错误:
未处理 System.ArgumentOutOfRangeException
Message="索引超出范围。必须为非负值并小于集合大小。
参数名: index"
请各位帮忙纠正
------解决方案--------------------
For l As Integer = 0 To DataGridView1.Rows.Count - 2
Dim sjdy As String = "insert into lsb(业务编码,`````) " _
& " VALUES ('" + DataGridView1.Rows(l).Cells(1).Value.ToString + "',``````) "
Dim sjdyCommand As OleDbCommand = New OleDbCommand(sjdy, myConn)
sjdyCommand.ExecuteNonQuery()
Next
应给没问题试过了