I'm running a query in Csharp against a Jet database. As it turns out, I used the wrong column name - the table doesn't have a column called "ID". I do have an autonumber column, but I called it "autoNum".
I used the wrong column name - but no exception threw! Instead, the query executed, and what is even more scary, it updated all the rows! (It was only supposed to update the one row based on the record ID/autonumber).
(As for it not throwing exceptions, this is not in a try-catch block, nor is it called by a try-catch block - I know this because other errors threw exceptions in that block).
Here's what the C# Immediate Window outputs:
? cmd.CommandText
"UPDATE SortedEobs SET PrintedBy = @PrintedBy WHERE ID = @ID"
? cmd.Parameters.Count
2
? cmd.Parameters[0].ParameterName
"@PrintedBy"
? cmd.Parameters[1].ParameterName
"@ID"
? cmd.Parameters["@ID"].Value
52
What the heck is going on here? So I pasted the query into SQL view and ran it there. Oddly enough, Jet only popped up two param boxes. The first one was for "@PrintedBy". The second was "ID" - it was NOT "@ID". It then warned me "You are about to update 3 rows." Why didn't it ask me for "@ID"? That is, since "ID" isn't a real column name, shouldn't Access assume three params here:
ID
@Id
@PrintedBy
I used the wrong column name - but no exception threw! Instead, the query executed, and what is even more scary, it updated all the rows! (It was only supposed to update the one row based on the record ID/autonumber).
(As for it not throwing exceptions, this is not in a try-catch block, nor is it called by a try-catch block - I know this because other errors threw exceptions in that block).
Here's what the C# Immediate Window outputs:
? cmd.CommandText
"UPDATE SortedEobs SET PrintedBy = @PrintedBy WHERE ID = @ID"
? cmd.Parameters.Count
2
? cmd.Parameters[0].ParameterName
"@PrintedBy"
? cmd.Parameters[1].ParameterName
"@ID"
? cmd.Parameters["@ID"].Value
52
What the heck is going on here? So I pasted the query into SQL view and ran it there. Oddly enough, Jet only popped up two param boxes. The first one was for "@PrintedBy". The second was "ID" - it was NOT "@ID". It then warned me "You are about to update 3 rows." Why didn't it ask me for "@ID"? That is, since "ID" isn't a real column name, shouldn't Access assume three params here:
ID
@Id
@PrintedBy