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. Store multiple values

Store multiple values

Scheduled Pinned Locked Moved C#
questioncsharpdatabase
5 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.
  • B Offline
    B Offline
    Bahadir Cambel
    wrote on last edited by
    #1

    Hi , I have a checked listBox control , which stores multiple items.The thing is , I should store these values and then retrieve.How could I store these values in a SqlColumn ? ( I am sorry it could be an Sql Forum question but there could be a way using C# before Sql, so I decided to post it here.) Thanks a lot. Bahadir Cambel.

    M 1 Reply Last reply
    0
    • B Bahadir Cambel

      Hi , I have a checked listBox control , which stores multiple items.The thing is , I should store these values and then retrieve.How could I store these values in a SqlColumn ? ( I am sorry it could be an Sql Forum question but there could be a way using C# before Sql, so I decided to post it here.) Thanks a lot. Bahadir Cambel.

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      Bahadir Cambel wrote: How could I store these values in a SqlColumn ? Well, it seems to me you want more than one column. If you want to put all the fields of a checked item in the ListBox control into one column, then you should probably put them into a comma delimited string first. In either case, put your data into SqlParameters, like:

      SqlParameter param=new SqlParameter("@foo", myFooValue);

      Then add the parameter:

      cmd.Parameters.Add(param);

      Then do the ExecuteNonQuery call. Of course, I'm leaving out the creation of the SqlCommand cmd variable and some other stuff, but that's not relevant to your question. Marc MyXaml Advanced Unit Testing YAPO

      B 1 Reply Last reply
      0
      • M Marc Clifton

        Bahadir Cambel wrote: How could I store these values in a SqlColumn ? Well, it seems to me you want more than one column. If you want to put all the fields of a checked item in the ListBox control into one column, then you should probably put them into a comma delimited string first. In either case, put your data into SqlParameters, like:

        SqlParameter param=new SqlParameter("@foo", myFooValue);

        Then add the parameter:

        cmd.Parameters.Add(param);

        Then do the ExecuteNonQuery call. Of course, I'm leaving out the creation of the SqlCommand cmd variable and some other stuff, but that's not relevant to your question. Marc MyXaml Advanced Unit Testing YAPO

        B Offline
        B Offline
        Bahadir Cambel
        wrote on last edited by
        #3

        Thanks for the reply Marc, I thought in the same way , but I asked for that there may be a better solution. What about putting values into a class/struct,and then serialize it binary and put into a binary column ? Do you have any ideas ? Is it possible ? and could it be more efficient ?

        M 1 Reply Last reply
        0
        • B Bahadir Cambel

          Thanks for the reply Marc, I thought in the same way , but I asked for that there may be a better solution. What about putting values into a class/struct,and then serialize it binary and put into a binary column ? Do you have any ideas ? Is it possible ? and could it be more efficient ?

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #4

          Bahadir Cambel wrote: What about putting values into a class/struct,and then serialize it binary and put into a binary column ? You could do that, but you may encounter, at some point, the need to query the DB, and then you don't have very searchable data. Also, beware of the .NET binary formatter. It isn't very efficient. It encodes into hideous xml, actually! You'd have to do your own binary serialization if you want efficiency, but then again, you should probably rely on the server to keep things efficient, imo. Marc MyXaml Advanced Unit Testing YAPO

          B 1 Reply Last reply
          0
          • M Marc Clifton

            Bahadir Cambel wrote: What about putting values into a class/struct,and then serialize it binary and put into a binary column ? You could do that, but you may encounter, at some point, the need to query the DB, and then you don't have very searchable data. Also, beware of the .NET binary formatter. It isn't very efficient. It encodes into hideous xml, actually! You'd have to do your own binary serialization if you want efficiency, but then again, you should probably rely on the server to keep things efficient, imo. Marc MyXaml Advanced Unit Testing YAPO

            B Offline
            B Offline
            Bahadir Cambel
            wrote on last edited by
            #5

            Thanks a lot for the replies Marc.

            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