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. Wildcard Query using C# and Access

Wildcard Query using C# and Access

Scheduled Pinned Locked Moved C#
csharpcssdatabasehelpquestion
4 Posts 4 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.
  • Z Offline
    Z Offline
    zoroyster
    wrote on last edited by
    #1

    Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.

    D P M 3 Replies Last reply
    0
    • Z zoroyster

      Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I don't use Access anymore but the SQL should be closer to:

      "SELECT * FROM Assignee WHERE SN LIKE '%{0}%'"

      I'm not real sure about the % characters. They might be something else.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      • Z zoroyster

        Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.

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

        I consider that we could use 2 character '*' and '%' based on what I need In SQL query, we use "Select * frm Assignee WHERE SN like 'Th%'" In Crystal Report, we use CrystalReport1.DataDefinition.RecordSelectionFomular = "{Assignee.SN} like 'Th*'";

        It seem to be a solution or an answer.

        1 Reply Last reply
        0
        • Z zoroyster

          Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.

          M Offline
          M Offline
          Manoj Kumar Rai
          wrote on last edited by
          #4

          Hi, On microsoft access, we have 2 wild characters, "*" and "?". So the mistake is in using "=" instead of the LIKE. Try to use sentance as: daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN LIKE '*{0}*'", search), conn); and I hope it will work for you. Manoj

          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