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. Paramaterised access queries

Paramaterised access queries

Scheduled Pinned Locked Moved Database
databasecsharptutorialquestion
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
    Russell Jones
    wrote on last edited by
    #1

    I'm trying to build a form to search an access membership database in c# I want to be able to search by firstname and lastname to start with but sometimes i might not be able to remember how to spell the whole name so I want names that start with what I've typed in. OleDbCommand command = _databaseConnection.CreateCommand(); command.CommandText = "SELECT * FROM MEMBERS WHERE fname like '?*' AND lname like '?*'"; command.Parameters.Add(new OleDbParameter("fname",firstName)); command.Parameters.Add(new OleDbParameter("lname", lastName)); I seem to have tried every combination of ?* ?% '?*' etc. in the sql statement, does anyone know what the correct syntax is to do this? Cheers Russ

    L 1 Reply Last reply
    0
    • R Russell Jones

      I'm trying to build a form to search an access membership database in c# I want to be able to search by firstname and lastname to start with but sometimes i might not be able to remember how to spell the whole name so I want names that start with what I've typed in. OleDbCommand command = _databaseConnection.CreateCommand(); command.CommandText = "SELECT * FROM MEMBERS WHERE fname like '?*' AND lname like '?*'"; command.Parameters.Add(new OleDbParameter("fname",firstName)); command.Parameters.Add(new OleDbParameter("lname", lastName)); I seem to have tried every combination of ?* ?% '?*' etc. in the sql statement, does anyone know what the correct syntax is to do this? Cheers Russ

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try it without the quotes round the parameters; This should work:

      command.CommandText = "SELECT * FROM MEMBERS WHERE fname like '%'+?+'%' AND lname like '%'+?+'%'";

      Source[^]

      I are Troll :suss:

      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