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. VB type collections in C#

VB type collections in C#

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

    I put a message on this board a couple of hours ago, but I can't see it so I think I might have been bumped. anyway, I'll try again. I'm a very experienced (20Yrs +) VB developer, and have used classes and collections so much that I raise them without thinking of how I do them. now I'm trying to transfer to C# I'm trying to find a way of doing the same thing. I have an inventory table consisting of the following fields: ID - int SKU - string Description - string Unit - string QtyOnSite - double ValOnSite - double I can raise an inventory class, but now i want to read all the information from a sqlserver table into a collection of type inventory. Could any of you wizards give me a clue as to how to do this please? Chiefy

    N 1 Reply Last reply
    0
    • C CheifyW

      I put a message on this board a couple of hours ago, but I can't see it so I think I might have been bumped. anyway, I'll try again. I'm a very experienced (20Yrs +) VB developer, and have used classes and collections so much that I raise them without thinking of how I do them. now I'm trying to transfer to C# I'm trying to find a way of doing the same thing. I have an inventory table consisting of the following fields: ID - int SKU - string Description - string Unit - string QtyOnSite - double ValOnSite - double I can raise an inventory class, but now i want to read all the information from a sqlserver table into a collection of type inventory. Could any of you wizards give me a clue as to how to do this please? Chiefy

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      How would you do it in VB? Open a connection to the database, execute a command, iterate through the results, instantiate a class, add to a collection

      List myClasses = new List();
      IDataReader dr = cmd.ExecuteReader();
      while(dr.Read())
      {
      MyClass cls = new MyClas();
      cls.ID = dr.GetInt(0);
      ...
      myClasses.Add(myClass);
      }


      only two letters away from being an asset

      C 1 Reply Last reply
      0
      • N Not Active

        How would you do it in VB? Open a connection to the database, execute a command, iterate through the results, instantiate a class, add to a collection

        List myClasses = new List();
        IDataReader dr = cmd.ExecuteReader();
        while(dr.Read())
        {
        MyClass cls = new MyClas();
        cls.ID = dr.GetInt(0);
        ...
        myClasses.Add(myClass);
        }


        only two letters away from being an asset

        C Offline
        C Offline
        CheifyW
        wrote on last edited by
        #3

        it looks really easy like that. I'll give it a try when I get back to work. In VB6 I would raise a class 'Inventory' containing all the fields I've already mentioned. The class manager would then apply all the 'get and 'set' attributes to the class members (I'm probably not using the right descriptions here). I would then raise a collection of class Inventory. I then would connect to my database, return a recordset of Inventory, and iterate through it, adding the information into the fields of the collection: do until recordset.eof = true inventory collection .add (the columns of the inventory table) loop Thanks for you help C# is great....

        C 1 Reply Last reply
        0
        • C CheifyW

          it looks really easy like that. I'll give it a try when I get back to work. In VB6 I would raise a class 'Inventory' containing all the fields I've already mentioned. The class manager would then apply all the 'get and 'set' attributes to the class members (I'm probably not using the right descriptions here). I would then raise a collection of class Inventory. I then would connect to my database, return a recordset of Inventory, and iterate through it, adding the information into the fields of the collection: do until recordset.eof = true inventory collection .add (the columns of the inventory table) loop Thanks for you help C# is great....

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It will work pretty much the same way in C#, the code only changes slightly. You should have specified you meant VB6, I think the other reply assumed you were going from VB.NET to C#, because VB6 has been obsolete for almost a decade.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          C 1 Reply Last reply
          0
          • C Christian Graus

            It will work pretty much the same way in C#, the code only changes slightly. You should have specified you meant VB6, I think the other reply assumed you were going from VB.NET to C#, because VB6 has been obsolete for almost a decade.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            C Offline
            C Offline
            CheifyW
            wrote on last edited by
            #5

            Thanks Christian, I'm going to try it now. sorry about the misunderstanding about VB6, I tend to think in that language. I know it's been obsolete for a long time, but there is still lots of VB6 code out there. I've not forgiven Uncle Billy for ditching it like that, although I can understand why. Chiefy

            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