插入语句的语法错误位于..... [英] Syntax error in Insert into statement at.....

查看:69
本文介绍了插入语句的语法错误位于.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用Vb.net,Access2007和Wind7.我收到此类错误消息..

cmd.ExecuteNonQuery()引发的运行时异常:System.Data.OleDb.OleDbException-INSERT INTO语句中的语法错误.

问题是此查询不适用于我的vb.net代码,但适用于msaccess"sqlview".

Hi,

I am using Vb.net,Access2007 and Wind7. I am getting this type of error msg..

cmd.ExecuteNonQuery() Run-time exception thrown : System.Data.OleDb.OleDbException - Syntax error in INSERT INTO statement.

Problem is that this query is not working in my vb.net code but it is working in msaccess "sqlview".

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strquery As String = "Insert Into Images (PatientID,Image,ImageNumber) VALUES (''patient0050'',''patient00501.JPG'',''1'')"
        Dim con As New OleDbConnection(objclsvariable.constr)
        Dim cmd As New OleDbCommand(strquery, con)
        con.Open()
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try

        con.Close()

    End Sub


如何解决此问题,将不胜感激.........
谢谢
穆克什

[edit]添加了代码块-OriginalGriff [/edit]


how can resolve this problem any one help will be appreciate.........
thank
mukesh

[edit]Code block added - OriginalGriff[/edit]

推荐答案

首先,我强烈建议您使用参数,然后使用内联查询. ]在您的表格名称周围见下文
First of all i would strongly recommend to use parameters then using inline query.Now second thing try putting [] around your table name. See below
Dim strquery As String = "Insert Into [Images] (PatientID,Image,ImageNumber) VALUES (''patient0050'',''patient00501.JPG'',''1'')"



这应该可以解决您的问题.下面的链接将告诉您有关参数化查询以及如何使用它的信息.

http://www.mikesdotnetting.com/Article/26/ASP.NET中带有MS-Access的参数查询 [



This should solve your problem.The link below will tell you about parameterized query and how to use it.

http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access[^]


这篇关于插入语句的语法错误位于.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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