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