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. facing problems with Dictonary object

facing problems with Dictonary object

Scheduled Pinned Locked Moved C#
databasehelpquestion
3 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.
  • Y Offline
    Y Offline
    yadlaprasad
    wrote on last edited by
    #1

    Hi All, I have one sample sql query and in where condition i need to put one value which is coming from dictonary object. sample sql query: select * from XYZ where column1= {0} so, i used string.Format(sql,searchvalue), sql: query with where condition searchvalue: Dictonaryobject(holds key and value) but while debugging it is not replacing dictionary value and it is replacing text like 'System.Collections.Generic.Dictionary`2[System.String,System.String]' i am a bit confused why it is not replacing with dictionary value. can anybody help on this?

    fttyhtrhyfytrytrysetyetytesystryrty

    A OriginalGriffO 2 Replies Last reply
    0
    • Y yadlaprasad

      Hi All, I have one sample sql query and in where condition i need to put one value which is coming from dictonary object. sample sql query: select * from XYZ where column1= {0} so, i used string.Format(sql,searchvalue), sql: query with where condition searchvalue: Dictonaryobject(holds key and value) but while debugging it is not replacing dictionary value and it is replacing text like 'System.Collections.Generic.Dictionary`2[System.String,System.String]' i am a bit confused why it is not replacing with dictionary value. can anybody help on this?

      fttyhtrhyfytrytrysetyetytesystryrty

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      yadlaprasad wrote:

      so, i used string.Format(sql,searchvalue),

      You need to use searchvalue["..."] where ... will be your key value. If you directly use searchvalue you will only get System.Collections.Generic.Dictionary`2.

      There are only 10 types of people in this world — those who understand binary, and those who don't.

      1 Reply Last reply
      0
      • Y yadlaprasad

        Hi All, I have one sample sql query and in where condition i need to put one value which is coming from dictonary object. sample sql query: select * from XYZ where column1= {0} so, i used string.Format(sql,searchvalue), sql: query with where condition searchvalue: Dictonaryobject(holds key and value) but while debugging it is not replacing dictionary value and it is replacing text like 'System.Collections.Generic.Dictionary`2[System.String,System.String]' i am a bit confused why it is not replacing with dictionary value. can anybody help on this?

        fttyhtrhyfytrytrysetyetytesystryrty

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        To add to Abinhavs' answer: Don't do it that way anyway! When you do, you leave your database open to an SQL injection attack[^] Do it this way

        SqlCommand cmd = new SqlCommand("SELECT * FROM xyz WHERE column1=@SV");
        cmd.Parameters.AddWithValue("@SV", searchvalue);

        Note that the convention is SQL keywords in uppercase, tablenames and fields lowercase.

        All those who believe in psycho kinesis, raise my hand.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        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