gpt4 book ai didi

c# - INSERT 语句中的错误信息

转载 作者:太空宇宙 更新时间:2023-11-03 18:12:52 24 4
gpt4 key购买 nike

我认为我的 INSERT 语句有问题。当我运行我的代码时,错误消息显示:

Line: 5
Error: Sys.WebForms.PageRequestManagerServerErrorException: Incorrect syntax near ','.

我的 where 子句有问题吗?

这是我的INSERT语句:

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

这就是我在 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);

最佳答案

使用 AND 而不是 , 来分隔 WHERE 子句中的条件。你必须这样写:

INSERT into AppointmentDetails (SelectedApptDate, SelectedApptStartTime,
SelectedApptEndTime, SelectedWeddingPlanner)
SELECT ApptID
from Appointment
INNER JOIN Appointment ON Appointment.ApptID = AppointmentDetails.ApptID
WHERE SelectedApptDate = @SelectedApptDate
AND SelectedApptStartTime = @SelectedApptStartTime
AND SelectedApptEndTime = @SelectedApptEndTime
AND SelectedWeddingPlanner = @SelectedWeddingPlanner";

但是之后您将得到一个新的异常,因为您只选择一列插入到这四列中:SelectedApptDate、SelectedApptStartTime、SelectedApptEndTime、SelectedWeddingPlanner。您还必须在 SELECT 语句中指定其他三列。

关于c# - INSERT 语句中的错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11453711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com