MS ACCESS query

  • Thread starter Dave Harrington
  • Start date
D

Dave Harrington

Hi all -

I got a pretty basic question that's been bugging me today. I'm using
ASP.NET, C# and MS Access for a database driven application. I have a
datagrid that will populate based on a registered user's access level.
There are some instances where I'd like to use a basic OR statement in my
Access query, but I do not know the syntax. The statement I'd like to use
is below

cmd = new OleDbCommand("Select * FROM
"+Session["ClassroomSession"].ToString()+"WHERE AccessLevel=\"All\" OR
AccessLevel=\"Speaker\" ORDER BY ID", conn);

In this case, I'd like to populate the datagrid with all elements WHERE the
field "AccessLevel" is EITHER "All" OR "Speaker".

Please help!

Thanks in advance.

Dave Harrington
 
G

Guest

You need to enclose the strings in single quotes like this

cmd = new OleDbCommand("Select * FROM
"+Session["ClassroomSession"].ToString()+"WHERE AccessLevel= 'ALL' OR
AccessLevel='Speaker' ORDER BY ID", conn);
 
P

Paul Clement

¤ Hi all -
¤
¤ I got a pretty basic question that's been bugging me today. I'm using
¤ ASP.NET, C# and MS Access for a database driven application. I have a
¤ datagrid that will populate based on a registered user's access level.
¤ There are some instances where I'd like to use a basic OR statement in my
¤ Access query, but I do not know the syntax. The statement I'd like to use
¤ is below
¤
¤ cmd = new OleDbCommand("Select * FROM
¤ "+Session["ClassroomSession"].ToString()+"WHERE AccessLevel=\"All\" OR
¤ AccessLevel=\"Speaker\" ORDER BY ID", conn);
¤
¤ In this case, I'd like to populate the datagrid with all elements WHERE the
¤ field "AccessLevel" is EITHER "All" OR "Speaker".
¤

You can also use the IN keyword:

SELECT *
FROM Table1
WHERE AccessLevel IN ('All','Speaker') ...


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top