"?" vs @param

string sql = "SELECT COUNT(*) ";
sql += "FROM athletes ";
sql += "WHERE category = ? ";
sql += "AND gender  = ? ";
 
VS
 
string sql = "SELECT COUNT(*) ";
sql += "FROM athletes ";
sql += "WHERE category = @category ";
sql += "AND gender  = @gender ";
 
 
 

Can I tell you how many hours I just spent on trying to get this *simple* query to work in Access via ADO.NET?  What is up with the "?" as parameters?  What happend to @param format like the SqlClient?  Why do they work in the Access Querybuilder itself, but not using ADO.NET?  Maybe I'm approaching this wrong.
Published Monday, March 21, 2005 1:40 PM by Travis
Filed under:

Comments

# re: "?" vs @param

Monday, March 21, 2005 5:03 PM by Paul Wilson
Access does allow @param as well as ? when using the OleDb classes, but its not true named parameters since you have to specify them in the correct order just like they were ?.

# re: "?" vs @param

Monday, March 21, 2005 11:48 PM by Jeff
I went through the same thing for something I didn't want to work on last year. Bah! I was annoyed.

# re: "?" vs @param

Tuesday, March 22, 2005 6:10 AM by Phil
Travis,

This is because one uses named parameters and one uses positional parameters, I'm writing about this at the moment and will post a blog entry over the next couple of days on how it's been improved in ADO.NET 2.0 so you don't have to care about which to use anymore.

Cheers,

Plip

# re: "?" vs @param

Tuesday, March 22, 2005 10:32 AM by Travis
I have been working with SQL for years now, this Access thing is just throwing me curves that I am not used to. Thanx for the tip Paul, you rock as always!

Looking forward to ADO.NET 2.0 Phil! Can't wait.

Leave a Comment

(required) 
(required) 
(optional)
(required)