简体   繁体   English

将内部联接更新语句添加到SQLdatasource

[英]Adding a Inner Join Update statement to an SQLdatasource

I've got a Gridview connected to an sqldatasource connected to sqlserver, I have added the Select statement to be this, and it works like i want it. 我已经将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

I now need to add an Update statement to just update the fields above when the user tries to edit the gridview, I tried this: 现在,我需要添加一条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

But it just wont work, and keeps giving me errors like Invalid syntax "S", or Invalid Syntax "Inner"... 但是它只是行不通,并且不断给我类似无效语法“ S”或无效语法“ Inner”的错误...

Your update statement is incorrect: 您的更新声明不正确:

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

EDIT 编辑

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM