0

I get this error when I run my program

OLEDB Exception Unhandled Syntax error in INSERT INTO statement

but I can't spot the error

This is my code:

Dim pictureData As Byte()
    Using ms As New MemoryStream
        PICPictureBox.Image.Save(ms, Imaging.ImageFormat.Jpeg)
        pictureData = ms.ToArray()
    End Using
    strsql1 = "insert into criminallist (CC#, FIRSTNAME, MIDDLENAME, LASTNAME, QUALIFIERS, ALIAS, GENDER, LASTKNOWNADDRESS, CRIMINALACTIVITY, CRIMINALINVOLVEMENT, AREAOFOPERATION, ISSUINGCOURT, REMARKS, DATEOFJAIL, TRACKERTEAM, PIC)values(@a0,@a1,@a2,@a3,@a4,@a5,@a6,@a7,@a8,@a9,@a10,@a11,@a12,@a13,@a14,@a15)"
    acscmd1.CommandText = strsql1
    acscmd1.Connection = acsconn1
    acscmd1.Parameters.AddWithValue("@a0", CC_TextBox.Text)
    acscmd1.Parameters.AddWithValue("@a1", FIRSTNAMETextBox.Text)
    acscmd1.Parameters.AddWithValue("@a2", MIDDLENAMETextBox.Text)
    acscmd1.Parameters.AddWithValue("@a3", LASTNAMETextBox.Text)
    acscmd1.Parameters.AddWithValue("@a4", QUALIFIERSComboBox.SelectedItem)
    acscmd1.Parameters.AddWithValue("@a5", ALIASTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a6", GENDERComboBox.SelectedItem)
    acscmd1.Parameters.AddWithValue("@a7", LAST_KNOWN_ADDRESSTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a8", CRIMINAL_ACTIVITYTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a9", CRIMINAL_INVOLVEMENTTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a10", AREA_OF_OPERATIONTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a11", ISSUING_COURTTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a12", REMARKSTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a13", DateTimePicker1.Value.Date)
    acscmd1.Parameters.AddWithValue("@a14", TRACKER_TEAMTextBox.Text)
    acscmd1.Parameters.AddWithValue("@a15", pictureData)
    acscmd1.ExecuteNonQuery()
    acscmd1.Dispose()
    MessageBox.Show("ADDED")
1

1 Answer 1

2

Obviously your statement is not correct or you would not be getting that error message. The issue is with the name of the first column. You can't have spaces or other special characters in a column name in SQL code without escaping it. That's done for Access using brackets, i.e.

insert into criminallist ([CC#], FIRSTNAME

A better option is to not use spaces, special characters or reserved words in column names or any other identifiers.

Sign up to request clarification or add additional context in comments.

7 Comments

I wonder whether they will then encounter the same error with ALIAS as a field name.
@HansUp, certainly worth considering but "Alias" is not an Access reserved word.
Is it also a problem that there are no spaces between the parentheses and the keyword 'values'? I'm not familiar enough with Access to know if that matters.
@ChrisDunaway, no, spaces aren't required except between keywords and/or identifiers. The lack of spaces within the second set of parentheses is no more a problem.
I was referring to the closing parenthesis of the list of columns and the keyword 'values'. In other words, does there need to be spaces before and after the keyword values? i. e. does this )values( need to be ) values (?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.