0

我有一个连接到连接到 sqlserver 的 sqldatasource 的 Gridview,我已经添加了这样的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”或无效语法“内部”......

4

1 回答 1

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
于 2012-12-06T15:17:34.847 回答