我有以下代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As New OleDb.OleDbCommand
Dim x As New Integer
Dim profID As New Integer
Dim date1 As New Date
date1 = #8:00:00 AM#
profID = 200900001
x = 0
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
'SerialPort1.Open()
'SerialPort1.Write("1")
'Dim readThis As String = SerialPort1.ReadChar()
'MsgBox(readThis)
'If readThis = 1 Then
'End If
'SerialPort1.Close()
cmd.CommandText = "UPDATE test " & _
"SET ProfLog='" & x & "'" & _
"WHERE ProfID=" & profID & " AND ProfTime=" & date1
cmd.ExecuteNonQuery()
MsgBox("DONE!")
End Sub
使用此代码,它表示有一个
Syntax error (missing operator) in query expression 'ProfID=200900001 AND ProfTime=8:00:00 AM'.
缺少什么操作员?
答案 0 :(得分:2)
您需要在where子句中重复#
表示法,以便访问权限知道该值是日期:
... & _
"WHERE ProfID = " & profID & " AND ProfTime = #" & date1 & "#"
(原因是,作为一个人为的例子,where x = 1/2/3
是一个日期或者 1除以2除以3 。)
答案 1 :(得分:0)
这一切都取决于目标。
对于MS Access - “ProfTime =#”& date1& “#”
对于SQL Server - “ProfTime ='”& date1& “'”