Link to home
Start Free TrialLog in
Avatar of Sivasan
SivasanFlag for United States of America

asked on

How to use OR condition from Combox box in VB.net

Hi There,
I have an application using Vb.net 2003. I have my backend as ms access.
I have made a oledbdataadapter1
with the following query
[WO #],  PO,  [Qty Ord]  Loc, ID FROM [Ftbl] WHERE  (Loc = ?)

the back end table Ftbl has data for 3 loc AZ, TX, AK

I have the function

Private Sub CBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBTN.Click
        Try
           
            OleDbDataAdapter1.SelectCommand.Parameters("Loc").Value = CoBox.Text
            ' CALL FUNCTION TO FILL
            FnR()
            'CHECK FOR ADDITION OF NEW ROW
            Dim changer As Smm = New Smm
            Dim newRow As DataRow = changer.Tables("Ftbl").NewRow()
            changer.Tables("Ftbl").Rows.Add(newRow)
            AddHandler OleDbDataAdapter1.RowUpdated, New System.Data.OleDb.OleDbRowUpdatedEventHandler(AddressOf OleDbDataAdapter1_RowUpdated)

        Catch ex As Exception
            MsgBox(ex.Message + vbCrLf + ex.Source & vbCrLf & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Error")
        End Try

I give the value to
OleDbDataAdapter1.SelectCommand.Parameters("Loc").Value = from a combox box
and on the Combo box I have the following list
AZ
TX
AR
AZ OR TX OR AR

AZ OR TX OR AR doesn't work when I want to see data for all 3 location. What is the right format so I can feed it "Loc" so it see it as
Loc = AZ or Loc = TX or Loc = AR  
or even better is there a way I can say ALL so my combo box list has it as
AZ
TX
AR
ALL    
so when they select ALLwill indicate  AZ or TX or Ar for LOC parameter and pull info for 3 loc.
I will appreciate if somebody can help me.
thanks
Avatar of derftoy
derftoy
Flag of United States of America image

I would use the SQL IN statement:

http://www.w3schools.com/sql/sql_in.asp

You will have to split out the data from the drop down list though.


Try that.
Avatar of Sivasan

ASKER

Hi Derftoy,
Thank for your reply, what does it mean "to split out the data from the drop down list"
thanks
Since your using paramaters for that one, I am not sure how the best way to go about it would be.  Not sure if a paramerterized item can have multiple values.

The SQL statement you have is a select with parameteres.  I don't use them.  I just build the sql and then execute it.

Avatar of Nasir Razzaq
I usually use two parameters in such a situation.

@applyfilter Bit
@filter Varchar

IF(@applyfilter = 1)
BEGIN
   Select ... Where columnname = @filter
END
ELSE
BEGIN
   Select ...
END


The above syntax is for SQL Server but I hope it requires little changes for Access.
Avatar of Sivasan

ASKER

Hi codecrusier
Thanks for your response,
is it possible to use if statement sql  on the oledbadapter or can I only use it under the Onclick event?
Right now I'm using oledbadpater to make the query.
thnks
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sivasan

ASKER

Hi Codecruser:
Though your answer was not exactly to my situation, I still used your concept and understood how to use the IF statement.
Under the Onclick event
i directly used the iF and checked the value of combo box, if value ='ALL'
i used one oledbadapter if not the other oledbadpater it worked.
Thanks a lot for your feed back.
Glad to help :-)