0

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);

                    conn.Open();
                    cmd.ExecuteNonQuery();

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

Thanks in advance

4
Contributors
7
Replies
30
Views
3 Years
Discussion Span
Last Post by Ranjitrathod15
0

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

0

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.

-1

hey..

try this:

VB

Dim transaction As SqlTransaction = Nothing

conn.Open()
transaction = conn.BeginTransaction()

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


''set your parameters here...


cmd.Transaction = transaction
            cmd.Prepare()
            cmdExecuteNonQuery()
            transaction.Commit()

Edited by newbie26

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.