VB '08 - Need to save unknown number of items to a single entry in access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Montravont
    New Member
    • Sep 2008
    • 10

    VB '08 - Need to save unknown number of items to a single entry in access

    So I'm making a character creator for a game I'm working on in my spare time.
    For each character, powers can be chosen. Based on the character type there is a very large level of variance for how many powers can possibly be chosen.

    What I need to be able to do is take a set of items from a listbox and save them to the access database. Each character is it's own row in the database.

    I have it set to be able to save everything but this to the database... but this is throwing me for a loop.

    Any suggestions would be appreciated.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .NET forum.

    Comment

    • Montravont
      New Member
      • Sep 2008
      • 10

      #3
      Nevermind, problem resolved. Saving the items from the list box as a comma seperated value to the database, then using split.string with "," as the delimiter to break it apart again.

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by Montravont
        Nevermind, problem resolved. Saving the items from the list box as a comma seperated value to the database, then using split.string with "," as the delimiter to break it apart again.
        Is there a reason you wouldn't link two tables by a key rather than using a CSV field. I personally can't stand CSV fields in a database - but that's just me. Maybe you have a good reason, but for 1 to many relationships, I would normally expect to see two tables, one for the parent record (i.e. the character) and one for the variable amount of items for that parent (i.e. the character's variable amount of powers).

        Comment

        • Montravont
          New Member
          • Sep 2008
          • 10

          #5
          Originally posted by balabaster
          Is there a reason you wouldn't link two tables by a key rather than using a CSV field. I personally can't stand CSV fields in a database - but that's just me. Maybe you have a good reason, but for 1 to many relationships, I would normally expect to see two tables, one for the parent record (i.e. the character) and one for the variable amount of items for that parent (i.e. the character's variable amount of powers).
          It's actually more for the creation of the powers as well as for what powers the character has. The main problem turned out to be more with the power creation. I have a table for the powers, and I have tables holding the different variables for the different types of items that can be added to a power at creation.

          CSV? Primarily because I'm not aware of (read: don't know) a better way to do it.

          CSV seems to work for what I'm trying to accomplish but I'm all for effeciency.

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            A better way (at least, from a relational DB perspective it's better) to do it is have another table, linked to the master record's ID, with each entry having it's own row, rather than being in one CSV field.

            Example:
            Code:
            //table 1
            IDt1 | CSVCol
            1    | a, b,c
            2    | a,d,e
            
            //table 2, making CSVCol unnecessary
            IDt2 | IDt2 | val
            1    |1     | a
            2    |1     | b
            3    |1     | c
            4    |2     | a
            5    |2     | d
            6    |2     | e

            Comment

            Working...