Hi I've ran into this error and have been looking at it for about an hour now and can't get it fixed.

 cmd.CommandText = "INSERT INTO Appointments (ClientName, Period, Time, Treatment, Stylist) VALUES (@cName, @cDate, @cTime, @cTreat, @cStylist)";
                    cmd.CommandType = CommandType.Text;

                    cmd.Parameters.AddWithValue("@cName", txtCName.Text);
                    cmd.Parameters.AddWithValue("@cDate", txtDate.Text);
                    cmd.Parameters.AddWithValue("@cTime", DDLTime.SelectedValue);
                    cmd.Parameters.AddWithValue("@cTreat", DDLTreat.SelectedValue);
                    cmd.Parameters.AddWithValue("@cStylist", DDLstylist.SelectedValue);


Can anyone see any errors in the code to result in the syntax error.

Thanks in advance

Recommended Answers

Is this different from this ?

If not, what's the error?

Jump to Post

what's the error?

Jump to Post

All 7 Replies

Is this different from this ?

If not, what's the error?

Yea this is a different error. When I run the page in debug it stops at line 11 with syntax error in INSERT INTO.

what's the error?

When I run the page in a browser, fill out the form and hit the submit button it doesn't do anything. So I placed a breakpoint on the button method so that when I run the application through debug it stops at the method and I can step through it, when I do this I can step through the code until it reaches cmd.ExecuteNonQuery(); It then comes up saying OleDbException was unhandled by user code, syntax error in INSERT INTO statement.

Query looks fine, perhaps one of the parameters is not set correctly.


try this:


Dim transaction As SqlTransaction = Nothing

transaction = conn.BeginTransaction()

Dim cmd As New SqlCommand("your insert statement", conn)

''set your parameters here...

cmd.Transaction = transaction

cheak datatype of colomn of your table and convert parameter type equal to that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.