Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Help for select statement

Help for select statement

Scheduled Pinned Locked Moved Database
databasejsonhelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prakash_Mishra
    wrote on last edited by
    #1

    Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards

    Prakash Mishra(Banglore,India)

    K A 2 Replies Last reply
    0
    • P Prakash_Mishra

      Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards

      Prakash Mishra(Banglore,India)

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Change the or to an and "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' and (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" Ben

      P 1 Reply Last reply
      0
      • K kubben

        Change the or to an and "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' and (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" Ben

        P Offline
        P Offline
        Prakash_Mishra
        wrote on last edited by
        #3

        HI i tried it before also but according to specification if i select only Category then also records should be displayed. if i put and there then i need to select at least one field from the or options. else it not show any record. Regards

        Prakash Mishra(Banglore,India)

        1 Reply Last reply
        0
        • P Prakash_Mishra

          Hi ALL In my application i wrote a query like this "select * from Cand_Information where Category= '" & DpCat.SelectedItem.Text & "' or (First_Name= '" & TxtFname.Text & "' or Last_Name= '" & TxtLname.Text & "' or Sex= '" & DpdownSex.SelectedItem.Text & "' )" But i want the Category field to be mandatory so i kept it outside the bracket. so that it should only display data with that particular Category. so rest of the fields are optional. How to write the correct one pl help Regards

          Prakash Mishra(Banglore,India)

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          Try this:

          string optionalFiters="";
          
          if(TxtFname.Text!="")
            optionalFiters+="  and First_Name= '" & TxtFname.Text + "'";
          
          if(TxtLname.Text!="")
            optionalFiters+="  and Last_Name= '" & TxtLname.Text + "'";
          
          if(DpdownSex.SelectedItem.Text!="")
            optionalFiters+="  and Sex= '" & DpdownSex.SelectedItem.Text + "'";
          

          Regards, Arun Kumar.A

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups