出现此错误System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常 [英] having this error An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

查看:137
本文介绍了出现此错误System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做我的最后一年的项目,并且正在做一个基于VB.net和Access数据库的库存控制系统.调试系统时,此错误不断出现.

I'm doing my final year project and i'm doing a inventory control system based on VB.net with Access database. I have this error that keeps coming up when I debug my system.

在System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常 其他信息:INSERT INTO语句中的语法错误.

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll Additional information: Syntax error in INSERT INTO statement.

下面是我的代码中存在错误的部分.表单中的这段代码使我可以将数据添加到数据库中.

Below is the part of my code that the error exists within. This piece of coding in the form allows me to add data into the database.

 cmd.CommandText = "INSERT INTO Product(Item ID, Item Name, Item Type, Quantity, Min Shelf Stock, Purchase Price, Note) " & _
                        " VALUES (" & Me.txtItemID.Text & ",'" & Me.txtItemName.Text & "','" & _
                        Me.cboItemType.Text & "','" & Me.txtQuantity.Text & "','" & _
                        Me.txtMinShelfStock.Text & "','" & Me.txtPurchasePrice.Text & "','" & _
                        Me.txtNote.Text & "')"
        cmd.ExecuteNonQuery()

推荐答案

cmd.ExecuteNonQuery()上放置一个断点,然后复制cmd.CommandText并直接在Access中执行它.这将告诉您查询的问题

Put a breakpoint on cmd.ExecuteNonQuery() and copy the cmd.CommandText and execute it directly in Access. That will tell you what's wrong with your query

修复查询后,开始使用命令参数.以下链接说明了如何进行

Once you fix your query, start using command parameters. The following link explain how to do paramaters

http ://msdn.microsoft.com/zh-CN/library/system.data.oledb.oledbcommand.parameters(v = vs.110).aspx

这篇关于出现此错误System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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