I believe there is something wrong with my INSERT statement here. When I run my code, the error message shows:
Line: 5
Error: Sys.WebForms.PageRequestManagerServerErrorException: Incorrect syntax near ‘,’.
Is is something wrong in my where clause?
Here is my INSERT statement:
INSERT into AppointmentDetails (SelectedApptDate, SelectedApptStartTime,
SelectedApptEndTime, SelectedWeddingPlanner)
SELECT
ApptID
from
Appointment
INNER JOIN
Appointment ON Appointment.ApptID = AppointmentDetails.ApptID
WHERE
SelectedApptDate = @SelectedApptDate,
SelectedApptStartTime = @SelectedApptStartTime,
SelectedApptEndTime = @SelectedApptEndTime,
SelectedWeddingPlanner = @SelectedWeddingPlanner
This is how I call it from C#:
command.CommandText = "INSERT into AppointmentDetails (SelectedApptDate, SelectedApptStartTime, SelectedApptEndTime, SelectedWeddingPlanner) SELECT ApptID from Appointment INNER JOIN Appointment ON Appointment.ApptID = AppointmentDetails.ApptID WHERE SelectedApptDate = @SelectedApptDate, SelectedApptStartTime = @SelectedApptStartTime, SelectedApptEndTime = @SelectedApptEndTime, SelectedWeddingPlanner = @SelectedWeddingPlanner";
command.Connection = connection;
command.Parameters.AddWithValue("@SelectedApptDate", dateSelected);
command.Parameters.AddWithValue("@SelectedApptStartTime", timeStart);
command.Parameters.AddWithValue("@SelectedApptEndTime", timeEnd);
command.Parameters.AddWithValue("@SelectedWeddingPlanner", weddingplanner);
Use
ANDinstead of,to separate between the conditions in theWHEREclause. You have to write it this way:However you will got a new exception after that, since you only select one column to insert into these four columns:
SelectedApptDate, SelectedApptStartTime, SelectedApptEndTime, SelectedWeddingPlanner. You have to specify the other three columns as well in theSELECTstatement.