using (SqlCommand command = new SqlCommand(
"WITH CTE AS (SELECT ROW_NUMBER() OVER (ORDER BY ID) AS RowNumber, Name, Website, Username, Password, Extras, CategoryIn" +
"FROM Accounts WHERE CategoryIn = @category) " +
"UPDATE CTE SET Name = @name, Website = @website, Username = @username, Password = @password, Extras = @extras, CategoryIn = @category WHERE RowNumber = @id", connection))
{
connection.Open();
command.Parameters.AddWithValue("@category", category);
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@name", name);
command.Parameters.AddWithValue("@website", website);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
command.Parameters.AddWithValue("@extras", extras);
command.ExecuteNonQuery();
}
我有一些代码来更新表,除了列CategoryIn
之外,它还可以更新。我猜它与CTE和WHERE CategoryIn = @category
部分有关。有人可以指点我吗?