我有一个Gridview连接到连接到sqlserver的sqldatasource,我已经添加了Select
语句,它就像我想要的那样。
SELECT S.[ID], S.[Survey_Name], S.[Start_Date], S.[End_Date], C.[Category_Name], S.[Username], S.[Picture],S.[Audience] FROM [Survey] S
Inner Join
Category C On S.Category_ID = C.ID
我现在需要添加一个Update
语句,以便在用户尝试编辑gridview时更新上面的字段,我试过这个:
UPDATE
Survey S
INNER JOIN
Category C
On S.Category_ID = C.ID
SET
S.Survey_Name=@Survey_Name,
S.Start_Date=@Start_Date,
S.End_Date = @End_Date,
C.Category_Name =@Category_Name,
S.Username = @Username,
S.Audience=@Audience
Where
ID=@ID
但是它不会起作用,并且一直给我一些错误,比如无效的语法“S”或无效的语法“内部”...
答案 0 :(得分:4)
您的更新声明不正确:
UPDATE Survey
SET
Survey.Survey_Name=@Survey_Name,
Survey.Start_Date=@Start_Date,
Survey.End_Date = @End_Date,
C.Category_Name = @Category_Name,
Survey.Username = @Username,
Survey.Audience=@Audience
FROM Survey S
INNER JOIN Category C
On S.Category_ID = C.ID
Where
S.ID=@ID
修改强>
UPDATE Survey
SET
Survey_Name=@Survey_Name,
Start_Date=@Start_Date,
End_Date = @End_Date,
Category_ID =C.ID,
Username = @Username,
Audience=@Audience
FROM Survey S
INNER JOIN Category C
On C.Category_Name = @Category_Name
WHERE
S.ID=@ID