问题描述
我在VB 2008中使用下面的代码来更新MS Access 2010中的表。它没有更新,也没有错误。以下代码有什么问题。
Hi, I am using below code in VB 2008 to update a table in MS Access 2010. Its not updating, no error as well. Whats is wrong with below code.
Dim cons, ins As String
cons = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Queue Manager - Offline\Queue Manager - Offine.accdb"
Dim con As New OleDbConnection(cons)
con.Open()
Dim cmd As New OleDbCommand
ins = "UPDATE OrderInfo SET InitialBatchID ='" & 5000 & "' WHERE 'GLID Number' = '" & TextBox9.Text & "'"
cmd.CommandText = ins
cmd.Connection = con
cmd.ExecuteNonQuery()
cmd.Dispose()
MsgBox("success")
con.Close()
推荐答案
cons = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Persist Security Info=False;"
2)更新声明可能有误!
a)如果 InitialBatchID
和 GLID编号
是数字字段,你应该删除'
左右的值。
b )如果字段名称在单词之间包含空格,则应在其周围添加 []
括号: [GLID编号]
而不是'GLID编号'
最后:
如果可执行文件位于同一文件夹中,你需要将它移动到另一个文件夹。
OriginalGriff是对的。您应该使用参数化查询。
2) Update statement could be wrong!
a) If InitialBatchID
and GLID number
are numeric fields, you should remove '
arounding values.
b) If field name contains space between words, you should add []
bracket around it: [GLID number]
instead of 'GLID number'
Finally:
If executable is in the same folder, you need to move it into another folder.
OriginalGriff is right. You should use parametrized queries.
这篇关于数据库没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!