我想从我的数据库更新记录。但是当我点击更新按钮时,总会发生这种情况。
这是我的代码。 请注意,[Probationary_Date],[LeaveEffectivity]和[Promoted]的数据类型为DATE / TIME ..
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
If btnEdit.Text = "EDIT" Then
btnEdit.Text = "UPDATE"
btnAdd.Enabled = False
ACCOUNT_RECHECK()
AdminValidation()
Else
If txtFname.Text = "" Or txtLname.Text = "" Or cmbType.Text = "" Or cmbGender.Text = "" Or txtSL.Text = "" Or txtVL.Text = "" Or cmbML.Text = "" Or txtPL.Text = "" Or txtSPL.Text = "" Or cmbVaw.Text = "" Or cmbSLFW.Text = "" Or txtSIL.Text = "" Or lblStatus.Text = "" Then
MsgBox("EMPTY FIELDS! ENTRY REQUIRED!")
btnEdit.Text = "UPDATE"
KondisyonOne()
Else
btnEdit.Text = "EDIT"
btnAdd.Enabled = True
TAGA_DISABLE()
TAGA_DISABLEB()
TAGA_DISABLEC()
dbconnect.Open()
qUpdate = "UPDATE Employee_Profile set Employee_Fname='" & txtFname.Text & "', Employee_Lname='" & txtLname.Text & "', Employee_Type='" & cmbType.Text & "', Employee_Gender='" & cmbGender.Text & "', SLTB='" & txtSL.Text & "', VLTB='" & txtVL.Text & "', MLS='" & cmbML.Text & "', PLTB='" & txtPL.Text & "', SPL='" & txtSPL.Text & "', VAWCLS='" & cmbVaw.Text & "', SLFWS='" & cmbSLFW.Text & "', SILTB='" & txtSIL.Text & "', LWPT='" & txtLWP.Text & "', Probationary_Date='" & DTProDate.Text & ", LeaveEffectivity='" & LeaveAvaiEffOn.Text & "', Promoted='" & PrmotedOn.Text & "', IsPromoted='" & cmbPromoted.Text & "', OldOrNew='" & cmbN_O.Text & "'where Employee_ID='" & Val(txtID.Text) & "'"
dbcommand = New OleDbCommand(qUpdate, dbconnect)
dbcommand.ExecuteNonQuery()
MessageBox.Show("Record Successfully Updated!")
dbconnect.Close()
btnDelete.Enabled = False
btnAdd.Enabled = True
TAGA_CLEAR()
End If
End If
End Sub
我希望你能帮助我! :)提前谢谢。
答案 0 :(得分:0)
Date 值的字符串表达式必须包含在octothorpes中,如:#2017-08-09#
但是要查看如何使用参数(许多很多例子用于浏览)。
对于这样的情况,这会更容易。
答案 1 :(得分:0)
一些事情。
你的参数字符串有几个拼写错误。 Probationary_Date没有关闭的撇号,你可能真的应该在最后的撇号和SQL命令的WHERE子句之间留一个空格。
此外,您应该将日期值包含在#yYYY-MM-DD#格式的哈希/章节中,而不是撇号。
答案 2 :(得分:0)
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
If btnEdit.Text = "EDIT" Then
btnEdit.Text = "UPDATE"
btnAdd.Enabled = False
ACCOUNT_RECHECK()
AdminValidation()
Else
If txtFname.Text = "" Or txtLname.Text = "" Or cmbType.Text = "" Or cmbGender.Text = "" Or txtSL.Text = "" Or txtVL.Text = "" Or cmbML.Text = "" Or txtPL.Text = "" Or txtSPL.Text = "" Or cmbVaw.Text = "" Or cmbSLFW.Text = "" Or txtSIL.Text = "" Or lblStatus.Text = "" Then
MsgBox("EMPTY FIELDS! ENTRY REQUIRED!")
btnEdit.Text = "UPDATE"
KondisyonOne()
Else
btnEdit.Text = "EDIT"
btnAdd.Enabled = True
TAGA_DISABLE()
TAGA_DISABLEB()
TAGA_DISABLEC()
dbconnect.Open()
qUpdate = "UPDATE Employee_Profile set Employee_Fname='" & txtFname.Text & "', Employee_Lname='" & txtLname.Text & "', Employee_Type='" & cmbType.Text & "', Employee_Gender='" & cmbGender.Text & "', SLTB='" & txtSL.Text & "', VLTB='" & txtVL.Text & "', MLS='" & cmbML.Text & "', PLTB='" & txtPL.Text & "', SPL='" & txtSPL.Text & "', VAWCLS='" & cmbVaw.Text & "', SLFWS='" & cmbSLFW.Text & "', SILTB='" & txtSIL.Text & "', LWPT='" & txtLWP.Text & "', Probationary_Date=#" & DTProDate.Text & "#, LeaveEffectivity=#" & LeaveAvaiEffOn.Text & "#, Promoted=#" & PrmotedOn.Text & "#, IsPromoted='" & cmbPromoted.Text & "', OldOrNew='" & cmbN_O.Text & "' where Employee_ID=" & txtID.Text
dbcommand = New OleDbCommand(qUpdate, dbconnect)
dbcommand.ExecuteNonQuery()
MessageBox.Show("Record Successfully Updated!")
dbconnect.Close()
btnDelete.Enabled = False
btnAdd.Enabled = True
TAGA_CLEAR()
TAGA_REFRESH()
End If
End If
End Sub
这是我使用的代码。它的工作原理:)谢谢你们! :)