我试图在我在其他表上插入新记录后更新表,但每次在成功添加记录后运行代码时我都会收到错误消息(update语句中的语法错误)。我使用MS ACCESS 2007作为我的数据库继承我的代码:
谢谢你的推荐
Public Sub addnew()
Dim add As String = String.Empty
add &= "insert into output_tbl(assycde,model_id,unit_serial,barcoded_serial_qty,Time_stamp,plan_id)"
add &= " values "
add &= "('" & cmbassycode.Text & "','" & txtmodel.Text & "','" & txtunitserial.Text & "','" & txtbs.Text & "','" & dtimestamp.Text & "','" & txtplanid.Text & "');"
Dim connection1 As String = ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\tepisql02\System\ProdSched\planning.accdb;Persist Security Info=False;")
Using conn1 As New OleDb.OleDbConnection(connection1)
Using cmd1 As New OleDb.OleDbCommand(add)
With cmd1
.Connection = conn1
.CommandType = CommandType.Text
.CommandText = add
End With
Try
conn1.Open()
If cmbassycode.Text = "" Then
MsgBox("Please Select A Assycode")
End If
cmd1.ExecuteNonQuery()
MsgBox("New Output Succesfuly Added")
Dim int As Integer = 1
Integer.TryParse(txtbs.Text, int)
txtbs.Text = (int + 1)
txtunitserial.Clear()
conn1.Close()
'End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
Dim countbar As String = DataGridView1.RowCount + 1
Dim updcountactive As String = String.Empty
updcountactive &= "Update setplan set Count=" & countbar & " , Actual='" & dtimestamp.Text & "' "
updcountactive &= "where ID=" & txtplanid.Text & ";"
MsgBox(updcountactive)
Dim connection2 As String = ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\tepisql02\System\ProdSched\planning.accdb;Persist Security Info=False;")
Using conn2 As New OleDb.OleDbConnection(connection2)
Using cmd2 As New OleDb.OleDbCommand(updcountactive)
With cmd2
.Connection = conn2
.CommandType = CommandType.Text
.CommandText = updcountactive
End With
Try
conn2.Open()
cmd2.ExecuteNonQuery()
conn2.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Sub
答案 0 :(得分:0)
希望这有帮助!
' updcountactive& ="其中ID =" &安培; txtplanid.Text& &#34 ;;"'
" txtplanid.Text"这返回一个字符串值, ID字段在表中是否为整数,那么它不起作用
updcountactive& ="其中ID =" &安培; convert.int32(txtplanid.Text)& "