1

I've been looking through my code for a while now and I can not see anything that would cause the following error at cmd.ExecuteNonQuery():

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dllAdditional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

This is my code:

public void InsertReservation(Reservation reservation)
{ //To counter the unavailable Auto Increment in the database
    int ReservationID = 0;
    string query = "SELECT max(ReservationID) FROM Reservation";

    if (this.OpenConnection())
    {
    MySqlCommand cmd = new MySqlCommand(query, connection);
    ReservationID = (Int32)cmd.ExecuteScalar();
    CloseConnection();
    }

    ReservationID++;
    string query2 = "INSERT INTO `Reservation`(`ReservationID`, `CarID`, `CustomerID`, `Startdate`, `Enddate`, `Confirmed`, `Kilometres`, `Pickupcity`, `Pickupstreetname`, `Pickupstreetnumber`, `Pickupstreetnumbersuffix`, `Paid`, `Comment`) VALUES(@reservationid,@carid,@customerid,@startdate,@enddate,@confirmed,@Kilometres,@pickupcity,@pickupstreetname,@pickupnumber,@pickupnumbersuffix,@paid,@comment";
    if (this.OpenConnection())
    {
        int convertCofnfirmedToInt;
        int convertPaidtoInt;
        MySqlCommand cmd = new MySqlCommand(query2, connection);
        cmd.Parameters.AddWithValue("@reservationid", ReservationID);
        cmd.Parameters.AddWithValue("@carid", reservation.carID);
        cmd.Parameters.AddWithValue("@customerid", reservation.customerID);
        cmd.Parameters.AddWithValue("@startdate", reservation.startdate);
        cmd.Parameters.AddWithValue("@enddate", reservation.enddate);
        cmd.Parameters.AddWithValue("@confirmed", reservation.);
        cmd.Parameters.AddWithValue("@Kilometres", reservation.kilometres);
        cmd.Parameters.AddWithValue("@pickupcity", reservation.pickupcity);
        cmd.Parameters.AddWithValue("@pickupstreetname", reservation.pickupstreetname);
        cmd.Parameters.AddWithValue("@pickupnumber", reservation.pickupstreetnumber);
        cmd.Parameters.AddWithValue("@pickupnumbersuffix", reservation.pickupstreetnumbersuffix);
        cmd.Parameters.AddWithValue("@paid", paidbool);
        cmd.Parameters.AddWithValue("@comment", reservation.comment);


        cmd.ExecuteNonQuery();
        this.CloseConnection();
    }

}    

If someone could help me out, that would be great!

1 Answer 1

2

Add closing round parenthesis ) at the end of your sql INSERT:

string query2 = "INSERT INTO `Reservation`(`ReservationID`, `CarID`, `CustomerID`, `Startdate`, `Enddate`, `Confirmed`, `Kilometres`, `Pickupcity`, `Pickupstreetname`, `Pickupstreetnumber`, `Pickupstreetnumbersuffix`, `Paid`, `Comment`) VALUES(@reservationid,@carid,@customerid,@startdate,@enddate,@confirmed,@Kilometres,@pickupcity,@pickupstreetname,@pickupnumber,@pickupnumbersuffix,@paid,@comment)";
Sign up to request clarification or add additional context in comments.

Comments

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.