Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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

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

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 11-Dec-19 21:40pm
v3
Comments
Uday P.Singh 16-Jun-11 3:46am    
tell us the exact error message
walterhevedeich 16-Jun-11 3:46am    
What's the exact error message?
mukesh_panth 16-Jun-11 4:34am    
cmd.ExecuteNonQuery() Run-time exception thrown : System.Data.OleDb.OleDbException - Syntax error in INSERT INTO statement.

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')"


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[^]
 
Share this answer
 
Try changing the insert query to like given below -

Dim strquery As String = "Insert Into Images (PatientID,[Image],ImageNumber) VALUES ('patient0050','patient00501.JPG','1')"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900