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. General Programming
  3. C#
  4. Database search

Database search

Scheduled Pinned Locked Moved C#
csharphelpdatabasetutorialquestion
2 Posts 2 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.
  • R Offline
    R Offline
    Rmokkenstorm
    wrote on last edited by
    #1

    I have a problem I'm busy writing a C#.NET project but walked into a problem. I've got a Form With 3 Textboxes a Button and a DataGrid. If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data. the Selectcommand: Select colom1, colum2, colom3, colom4, colom5 From Tabel1 Where (Colom1 = :param2) and (Colom2 = :param3) and (Colom3 = :param4) But now i want it like This: If i Typ a value for the first and last colom and nog the second one. I still want him te show me the data he found. If i do this now he says that he haven't got enough info to fill op my dataAdaptor. Wich is logic. But i realy don't have a clue how to do this.. can you help me?

    G 1 Reply Last reply
    0
    • R Rmokkenstorm

      I have a problem I'm busy writing a C#.NET project but walked into a problem. I've got a Form With 3 Textboxes a Button and a DataGrid. If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data. the Selectcommand: Select colom1, colum2, colom3, colom4, colom5 From Tabel1 Where (Colom1 = :param2) and (Colom2 = :param3) and (Colom3 = :param4) But now i want it like This: If i Typ a value for the first and last colom and nog the second one. I still want him te show me the data he found. If i do this now he says that he haven't got enough info to fill op my dataAdaptor. Wich is logic. But i realy don't have a clue how to do this.. can you help me?

      G Offline
      G Offline
      gnjunge
      wrote on last edited by
      #2

      Start using if statements to check which parameters to use in your SELECT query. something like:

      StringBuilder sb = new StringBuilder();
      sb.Append ("SELECT colom1, colum2, colom3, colom4, colom5 FROM Tabel1 ");
      sb.Append ("WHERE ");
      if (param2 != string.Empty)
      sb.Append("(Colom1 = :param2)");
      if (param3 != string.Empty)
      sb.Append("(Colom2 = :param3)");
      if (param4 != string.Empty)
      sb.Append("(Colom3 = :param4)");

      or if this is in a stored procedure, make IF statements in your stored procedure.

      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