Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The error keeps showing that there is wrong with my INSERT INTO statement, can somebody help me? Don't judge please. Thank you.

What I have tried:

VB
If MessageBox.Show("DO YOU WANT TO SAVE THIS RECORD?", "TIPAS FOODCOURT KIOSK", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    cm = New OleDbCommand("insert into tblmerchant (DESCRIPTION, PRICE, STATUS, CATEGORIES, IMAGE PATH)values(@DESCRIPTION,@PRICE,@STATUS,@CATEGORIES,@IMAGE PATH)", cn)

    With cm
        .Parameters.AddWithValue("@DESCRIPTION", descrip.Text)
        .Parameters.AddWithValue("@PRICE", price.Text)
        .Parameters.AddWithValue("@STATUS", status1.Text)
        .Parameters.AddWithValue("@CATEGORIES", categ.Text)
        .Parameters.AddWithValue("@IMAGE PATH", path1.Text)
        .ExecuteNonQuery()


    End With
Posted
Updated 8-Nov-22 8:23am
v4
Comments
CHill60 3-Nov-22 8:21am    
Please give the full error message
Hazel Ann Torno 3-Nov-22 9:27am    
hi, here's the error message

System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'


1 solution

You have a blank space in the column name IMAGE PATH, which causes the error. So you either need to put square brackets round it (see below), or better still use a column name without spaces, e.g. IMAGE_PATH.
VB
cm = New OleDbCommand("insert into tblmerchant (DESCRIPTION, PRICE, STATUS, CATEGORIES, [IMAGE PATH])values(@DESCRIPTION,@PRICE,@STATUS,@CATEGORIES,@IMAGE PATH)", cn)

As noted by Richard Deeming below, the parameter name is also incorrect.
 
Share this answer
 
v2
Comments
Richard Deeming 3-Nov-22 9:21am    
You'll also need to fix the parameter name, which also contains a space.
Richard MacCutchan 3-Nov-22 9:26am    
Yes, I forgot about that bit.
Hazel Ann Torno 3-Nov-22 9:33am    
Hi, there's a space in parameters
Richard MacCutchan 3-Nov-22 9:35am    
Yes, and you need to fix it.
Richard MacCutchan 3-Nov-22 9:57am    
You cannot do that for the parameter name, just change it to "@IMAGEPATH", without the space. And make sure you change it both places.

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