0

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?

2 Answers 2

0

do you need to delimit your parameter values with quotes?

AND LocSTATN_ORG_ID = "'" + @orgId + "'"
AND LocProj_ORG_ID = "'" + @orgId + "'"
2
  • 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... Commented Aug 20, 2010 at 19:44
  • 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? Commented Aug 20, 2010 at 19:57
0

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.

1
  • 1
    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. Commented Aug 20, 2010 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.