"?" 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.

4 Comments

  • 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 ?.

  • I went through the same thing for something I didn't want to work on last year. Bah! I was annoyed.

  • 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

  • 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.

Comments have been disabled for this content.