MS ACCESS query

Discussion in 'ASP .Net' started by Dave Harrington, Dec 5, 2005.

  1. 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
     
    Dave Harrington, Dec 5, 2005
    #1
    1. Advertising

  2. 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);


    "Dave Harrington" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?U3JpZGhhcg==?=, Dec 5, 2005
    #2
    1. Advertising

  3. Dave Harrington

    Paul Clement Guest

    On Mon, 5 Dec 2005 14:55:41 -0500, "Dave Harrington" <> wrote:

    ¤ 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)
     
    Paul Clement, Dec 6, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    1
    Views:
    1,025
    Marina Levit [MVP]
    Jan 30, 2006
  2. Anonymous
    Replies:
    0
    Views:
    1,550
    Anonymous
    Oct 13, 2005
  3. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    831
    David Gordon
    May 18, 2005
  4. Eric Nelson
    Replies:
    5
    Views:
    1,577
    Alexey Smirnov
    Feb 4, 2009
  5. Jon F.

    CAML Query: Multiple Query Fields Issue

    Jon F., May 12, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    774
    Jon F.
    May 12, 2004
Loading...

Share This Page