【发布时间】:2020-06-20 13:38:10
【问题描述】:
您好,我想将我的 ActivityClub 表与 Clubs 表进行内部连接,以便将其更新为 2 个表。但到目前为止,我的代码不起作用。我正在使用方法类和 SQL 数据库。 这是我得到 System.Data.SqlClient.SqlException 的错误:'关键字'INNER'附近的语法不正确。'
public int updateactivity(string clubname, string clubdesc, string activity, string achv)
{
int status = 0;
string updateSQL = "UPDATE ActivityClub SET club_desc=@desc, activity=@act, achievement=@acv INNER JOIN Clubs AS C1 ON C1.club_desc = Activity.club_desc WHERE club_name=@club";
Connect();
SqlCommand cmd = new SqlCommand(updateSQL, conn);
cmd.Parameters.AddWithValue("@club", clubname);
cmd.Parameters.AddWithValue("@desc", clubdesc);
cmd.Parameters.AddWithValue("@act", activity);
cmd.Parameters.AddWithValue("@acv", achv);
status = cmd.ExecuteNonQuery();
return status;
}
【问题讨论】:
-
请解释一下,没用是什么意思
-
我得到了这个异常
System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword 'INNER'.' -
你正在使用哪个数据库???
-
如果您需要更新多个表,则必须执行多个更新命令。
-
但是,如果您需要根据另一个表中的内容确定要更新一个表中的哪些行,则必须执行类似
Update a Set Bar=@Bar From TableToUpdate a Join AnotherTable b on a.Id = b.Aid Where b.Foo = @Foo的操作