views:

36

answers:

2

I'm having some trouble getting results from a c# OleDbCommand on an MS Access database. Here's my command:

SELECT START_DATE
FROM tblVisits
WHERE LocProj_IS_NUMBER = @projId
AND LocSTATN_IS_NUMBER = @statnId
AND LocSTATN_ORG_ID = @orgId
AND LocProj_ORG_ID = @orgId

If I call this using parameters, I get no results, BUT if I replace @orgId with 'GULN' then I get exactly what I expect. Programmatically, I'm getting the @orgId value from the SelectedValue property of a DropDownList. I'm baffled because this exact approach is working in a query to other tables in the same database.

Any ideas?

A: 

do you need to delimit your parameter values with quotes?

AND LocSTATN_ORG_ID = "'" + @orgId + "'"
AND LocProj_ORG_ID = "'" + @orgId + "'"
Beth
just tried that. no dice. This is the first time I'm querying an access database, and having not created it, am having trouble figuring out the quirks in the SQL to access translation...
Ryan Twilley
can you query the Access database from Access to check the syntax? Also, what are the data types for LocSTATN_ORG_ID and LocProj_ORG_ID?
Beth
A: 

So here's what worked. I replaced all of the parameter names with question marks (thanks to this post) No idea why my previous queries were working without a hitch. I'm guessing that trying to reference the same parameter twice was the main problem.

Ryan Twilley
You're new here, so just a point of order: even if you've answered your own question, it's perfectly acceptable to mark your own answer as Accepted. If you don't make an accepted answer, the question will continue to attract folks wanting to help out because they believe no answer has been found.
Cyberherbalist
Gotcha, thanks for looking out!
Ryan Twilley