I am having a bit of trouble with updating data with my DAL2 module.
I have the following, very simple code which will update or insert a row into a table:
var sb = new StringBuilder();
sb.Append("UPDATE Tab_Categories SET CategoryId = @1 WHERE TabId = @0");
sb.Append(" IF @@ROWCOUNT = 0");
sb.Append(" INSERT INTO Tab_Categories (TabId, CategoryId) VALUES (@0, @1)");
db.Execute(System.Data.CommandType.Text, sb.ToString(), new object[] { tabId, catId, });
But when the code runs my catch block logs the following: Must declare the scalar variable "@ROWCOUNT".
Which clearly means I need to escape the @ symbol in @@ROWCOUNT.
How do you normally work around the issue? Is it even possible?
I had a similar issue when trying to call a stored procedure with named parameter list in a similar fashion. Luckily I was able to get away with string.Format() by providing the list of values in the correct order. But I do not have the luxury of doing so this time.
Just in case, I know that in the name of good practice I should define an entity model and a controller and use those for CRUD operations but I really do not want to do that at this point in time.