首先,我想说感谢所有程序员,让这个网站如此高效的人!我很自豪地说,我获得的VB编程知识的80%是因为本网页中的所有示例和答案。无论如何,我正在为我的公司开发一个质量控制应用程序,并且在我的一个表单中有一个数据网格视图。用户可以对其进行更改,之后他/她必须将数据网格保存回MS Access数据库。我尝试了一切,但我无法将日期字段保存到数据库中。我检查了字段格式,数据库表的格式为"日期/时间" 这就是我所拥有的:
Dim sql As String
Try
For i As Integer = 0 To dataAddemdumView.RowCount - 1
sql = "UPDATE MasterRecordsT SET Fecha = '" & dataAddemdumView.Rows(i).Cells("Fecha").Value & "', Pass = " & dataAddemdumView.Rows(i).Cells("Pass").Value & ", Fail =
" & dataAddemdumView.Rows(i).Cells("Fail").Value & ", Employee = " & dataAddemdumView.Rows(i).Cells("Employee").Value & ", Gig = " & dataAddemdumView.Rows(i).Cells("Gig").Value & ", GigNotes =
'" & dataAddemdumView.Rows(i).Cells("GigNotes").Value & "', Department = '" & dataAddemdumView.Rows(i).Cells("Department").Value & "' WHERE ID = " & dataAddemdumView.Rows(i).Cells("ID").Value & ""
cmd = New OleDbCommand(sql, con)
con.Open()
da.UpdateCommand = con.CreateCommand()
da.UpdateCommand.CommandText = sql
da.UpdateCommand.ExecuteNonQuery()
con.Close()
Next
Catch ex As Exception
con.Close()
'MessageBox.Show("OPEX Quality encountered a problem, Try to reopen the application to solve issues", "Error 0002", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
非常感谢你的帮助!
答案 0 :(得分:0)
所以这将是最终的代码,它可以正常工作
Dim sql As String
Try
For i As Integer = 0 To dataAddemdumView.RowCount - 1
If Not dataAddemdumView.Rows(i).Cells("Fecha").Value Is DBNull.Value Then
sql = "UPDATE MasterRecordsT SET Fecha = '" & dataAddemdumView.Item("Fecha", i).Value & "', Pass = " & dataAddemdumView.Rows(i).Cells("Pass").Value & ", Fail =
" & dataAddemdumView.Rows(i).Cells("Fail").Value & ", Employee = " & dataAddemdumView.Rows(i).Cells("Employee").Value & ", Gig = " & dataAddemdumView.Rows(i).Cells("Gig").Value & ", GigNotes =
'" & dataAddemdumView.Rows(i).Cells("GigNotes").Value & "', Department = '" & dataAddemdumView.Rows(i).Cells("Department").Value & "' WHERE ID = " & dataAddemdumView.Rows(i).Cells("ID").Value & ""
cmd = New OleDbCommand(sql, con)
con.Open()
da.UpdateCommand = con.CreateCommand()
da.UpdateCommand.CommandText = sql
da.UpdateCommand.ExecuteNonQuery()
con.Close()
End If
Next
Catch ex As Exception
con.Close()
MsgBox(ex.Message)
'MessageBox.Show("OPEX Quality encountered a problem, Try to reopen the application to solve issues", "Error 0002", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try