数据库没有更新 [英] Database not updating

查看:85
本文介绍了数据库没有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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()

推荐答案

可能是任何事情:我们无法从中得知(我们无法测试你的代码,因为我们无法访问你的数据库。)



所以从调试器开始:在第一行放一个断点该代码,并在调试器中运行您的应用程序。当它到达断点时,执行将停止,让你单步执行代码,看看究竟发生了什么。



但请不要这样做。不要连接字符串以构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询。
Could be anything: we can't tell from that (and we can't test your code, because we don't have access to your database.)

So start with the debugger: put a breakpoint on the first line of that code, and run your app in the debugger. When it reaches the breakpoint, execution will stop, and let you step through your code and see exactly what is happening.

But please, don't do it like that. Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.


请阅读我对该问题的评论。



我看到至少2个上述行为的原因:

1)连接字符串不完整!

应该是:
Please, read my comment to the question.

I see at least 2 reasons of above behaviour:
1) Connection string is incomplete!
Should be:
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.


这篇关于数据库没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆