我在将数据从列表视图插入MySQL时遇到问题。这就是我到目前为止所拥有的。该错误表示列数与第1行的值计数不匹配
Dim sql As String
Dim con = New MySqlConnection("data source=localhost; user id=root; password=pwd; database=db;")
Dim cmd = New MySqlCommand
Dim lvitem As Object
Dim iCount As Integer
Dim iLoop As Integer
iCount = ListPayroll.Items.Count()
Try
If Not ListPayroll.Items.Count = 0 Then
Do Until iLoop = ListPayroll.Items.Count
lvitem = ListPayroll.Items.Item(iLoop)
With lvitem
con.Open()
sql = "INSERT INTO attendancelist (empno, line1, time1, line2, time2, line3, time3, line4, time4, line5, time5, line6, time6) values('" & .SubItems(0).text & "','" & .SubItems(1).text & "','" & .SubItems(2).Text & "','" & .SubItems(3).Text & "','" & .SubItems(4).Text & "','" & .SubItems(5).Text & "', '" & .SubItems(6).Text & "', '" & .SubItems(7).Text & "', '" & .SubItems(8).Text & "','" & .SubItems(9).Text & "', '" & .SubItems(10).Text & "', '" & .SubItems(11).Text & "', '" & .SubItems(12).Text & "', '" & .SubItems(13).Text & "')"
cmd.Connection = con
cmd.CommandText = sql
cmd.ExecuteNonQuery()
End With
iLoop = iLoop + 1
lvitem = Nothing
con.Close()
MessageBox.Show("Record Saved!")
Loop
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
答案 0 :(得分:0)
您正尝试将14个值插入13列。