我编写了一个代码将文本框的值存储到sql数据库中,它工作正常,但是当我尝试将datagridview的值插入sql数据库时,它既不起作用也没有返回错误......
Private Sub savenprint()
If Not db.con.State = ConnectionState.Open Then
db.dbOpen()
With db.cmd
.Connection = db.con
.CommandText = "INSERT INTO Reciept VALUES ('" & txtRecieptNo.Text & "','" & TransDate.Text & "','" & txtSubTotal.Text & "') "
.ExecuteNonQuery()
End With
'to save data of DGVOrderedList into RecieptDescription
For Each row As DataGridViewRow In DGVorderedList.Rows
MsgBox(row.Cells(1).Value)
With db.cmd
.Connection = db.con
.CommandText = "INSERT INTO billDescription VALUES ('" & Val(txtRecieptNo.Text) & "','" & row.Cells(1).Value & "','" & row.Cells(2).Value & "','" & row.Cells(4).Value & "','" & row.Cells(3).Value & "','" & row.Cells(5).Value & "')"
End With
MsgBox("Record Saved!")
Next
End If
db.dbClose()
End Sub
最佳答案
With db.cmd
.Connection = db.con
.CommandText = "INSERT INTO billDescription VALUES ('" & Val(txtRecieptNo.Text) & "','" & row.Cells(1).Value & "','" & row.Cells(2).Value & "','" & row.Cells(4).Value & "','" & row.Cells(3).Value & "','" & row.Cells(5).Value & "')"
.ExecuteNonQuery()
End With
关于mysql - 我的代码没有将数据值存储到 Sql 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41866831/