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. Disabling character in combo box

Disabling character in combo box

Scheduled Pinned Locked Moved C#
helpquestiondatabase
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.
  • D Offline
    D Offline
    DougW48
    wrote on last edited by
    #1

    This question has 2 parts...either answer would fix a problem for me My problem is that I need to query a database, and one of my parameters is the text from a combo box. If the user puts an apostrophe, then this messes up my query. So here are my questions: How would I go about pre-processing a keypress event in a combo box so I can disable specific characters from ever being typed, such as the apostrophe? ~or~ How can I prevent an apostrophe (or probably quotes too) from screwing up transferring rows? (I'm getting the error when I use this data in a Crystal Report, and when I build a select command for a data adapter, and include the text which contains the apostrophe.) Thanks for any help, I apprecaite it :-D

    A H 2 Replies Last reply
    0
    • D DougW48

      This question has 2 parts...either answer would fix a problem for me My problem is that I need to query a database, and one of my parameters is the text from a combo box. If the user puts an apostrophe, then this messes up my query. So here are my questions: How would I go about pre-processing a keypress event in a combo box so I can disable specific characters from ever being typed, such as the apostrophe? ~or~ How can I prevent an apostrophe (or probably quotes too) from screwing up transferring rows? (I'm getting the error when I use this data in a Crystal Report, and when I build a select command for a data adapter, and include the text which contains the apostrophe.) Thanks for any help, I apprecaite it :-D

      A Offline
      A Offline
      Aryadip
      wrote on last edited by
      #2

      You can prevent apostrophe by placing 2 single apostrophe instead of one... i.e. string strName = "baby's day out"; ..."where name='"+strName+"'"; change "strName" like this : string strName = "baby''s day out" thus after the text has been entered in the combo parse the string for single apostrophe. If present replace that with double like above example and then use the string in ur query. hope this works... regards, Aryadip. Cheers !! and have a Funky day !!

      D 1 Reply Last reply
      0
      • A Aryadip

        You can prevent apostrophe by placing 2 single apostrophe instead of one... i.e. string strName = "baby's day out"; ..."where name='"+strName+"'"; change "strName" like this : string strName = "baby''s day out" thus after the text has been entered in the combo parse the string for single apostrophe. If present replace that with double like above example and then use the string in ur query. hope this works... regards, Aryadip. Cheers !! and have a Funky day !!

        D Offline
        D Offline
        DougW48
        wrote on last edited by
        #3

        Thank you, that worked very well! :-D:-D

        1 Reply Last reply
        0
        • D DougW48

          This question has 2 parts...either answer would fix a problem for me My problem is that I need to query a database, and one of my parameters is the text from a combo box. If the user puts an apostrophe, then this messes up my query. So here are my questions: How would I go about pre-processing a keypress event in a combo box so I can disable specific characters from ever being typed, such as the apostrophe? ~or~ How can I prevent an apostrophe (or probably quotes too) from screwing up transferring rows? (I'm getting the error when I use this data in a Crystal Report, and when I build a select command for a data adapter, and include the text which contains the apostrophe.) Thanks for any help, I apprecaite it :-D

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          This is what happens when you don't use parameterized commands! I know that I've given you code samples before for this. Creating a SQL command by concatenating your params together is arcane and should not be used in .NET. If you use a SqlCommand, for example, then you should add SqlParameters to its SqlCommand.Parameters collection property and use @_paramname_ in your query without quotes. The command will do what's necessary. See the documentation for the SqlParameter (or OleDbParameter, or any of the others) in the .NET Framework SDK. There are also a lot of other benefits to using parameterized commands, such as easy batch processing when you save the parameters as variables and simply update their Value property, then re-execute the command.

          Microsoft MVP, Visual C# My Articles

          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