MS ACCESS query

  • Thread starter Thread starter Dave Harrington
  • Start date 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
 
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);
 
¤ 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)
 
Back
Top