Results 1 to 3 of 3

Thread: [RESOLVED] Oledbcommand where....or....or

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    5

    Resolved [RESOLVED] Oledbcommand where....or....or

    Hi all,

    I need a quick response to my problem. I need to write an OLEDBCOMMAND that I cannot figure out how to structure. It should look for an access database for a specified value and check two column. If only one or both of the checked columns have specified value, it should select the row. For instance,
    COLUMN1............COLUM2....COLUMN3
    ROWx.................OK...........NOT OK
    ROWx.................OK...........OK
    ROWx................ NOT OK.....NOT OK

    It should be something like

    comm.CommandText = "Select * from table WHERE COLUMN1='" combobox.text & ''," & COLUMN2=OK "' OR '" & COLUMN3=OK & "'"

    It should return first and second rowx if combobox value is rowx.
    Thanks for your helps.
    Last edited by ew03; May 6th, 2013 at 01:59 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Oledbcommand where....or....or

    Well, we can give you a quick response, but it may not be a good one. I'm not even sure what the real question is. There are some missing & in your SQL statement, but that's probably just because you typed it freehand into the post, as you have the rest in place. There's also an issue with the "," that you concatenate in, as that isn't going to work, but I think that just replacing that with an AND might do, especially if you add some parentheses to make it clear whether the And or the Or takes precedence. You also seem to be using the right object.

    So what is it you are actually looking for?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    5

    Re: Oledbcommand where....or....or

    Hi Shaggy,

    Even though i could not state myself clearly, you greatly helped me with your suggestion with parantheses. It works like a charm. I changed my statement as,

    comm.CommandText = "Select * from table WHERE COLUMN1='" & ComboBox1.Text & "' AND (COLUMN2='OK' OR COLUMN3='OK')"

    Thanks a million.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width