|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to create generic object at run-time?single row of DataTable. Lets say I create class as follow: Public Class Participant Public ParticipantID As Int64 Public LastName As String Public FirstName As String End Class then I get a data from the database to DataTable and create array of objects typed as Participant: <WebMethod(Description:="Returns ArrayList")> _ Public Function GetParticipants() As Participant() <CUT> adapter.Fill(custDS, "myData") Dim arrList As New ArrayList For Each row As DataRow In custDS.Tables("myData").Rows Dim MyParticipant As New Participant With myParticipant .ParticipantID = row("ParticipantID") .LastName = row("LastName").ToString .FirstName = row("FirstName").ToString End With arrList.Add(myParticipant) Next Dim arrParticipant As Participant() = arrList.ToArray(GetType(Participant)) Return arrParticipant End Function What I like to accomplish is to create a generic class which could be use to accomodate data pull from any DataTable with various column numbers. In another words, when DataTable is populated I would like to enumarate a column collection and create as many items in my generic class as there are column in DataTable. Can this be done? Just to clarify, this is WebService function which is consume by Adobe Flex 2 client. This function works very well with Flex 2 but I like to write more generic one which would be able to return any set of rows from any SELECT query. Thanks in advance, John mojeza <naj***@hotmail.com> wrote in news:1178139077.955623.103050
@e65g2000hsc.googlegroups.com: > What I like to accomplish is to create a generic class which could be You can already enumerate the a datarow object (Columns is a collection).> use to accomodate data pull from any DataTable with various column > numbers. In another words, when DataTable is populated I would like to > enumarate a column collection and create as many items in my generic > class as there are column in DataTable. Can this be done? If you like to create something generic, you'll need to store each piece of data as a element in a collection, i.e.: MyObjectStore("Column1").Value = DataRow("Column1") MyObjectStore("Column2").Value = DataRow("Column2") etc. Otherwise if you like to create a truly dynamic type... I believe you can do this with reflection. However, I don't believe web services can handle that sort of object ... since you need the WSDL defintion beforehand. > If you like to create something generic, you'll need to store each piece of Could you please be more specific as to how I must declare> data as a element in a collection, i.e.: > > MyObjectStore("Column1").Value = DataRow("Column1") > MyObjectStore("Column2").Value = DataRow("Column2") > etc. MyObjectStore (what type): Dim MyObjectStore As ???? and how to dimension MyObjectStore in order to accomodate all colums in a given DataRow. Thank you. mojeza <naj***@hotmail.com> wrote in
Show quoteHide quote news:1178143583.692231.321230@n59g2000hsh.googlegroups.com: Please read up on arrays, lists, and collections:>> If you like to create something generic, you'll need to store each >> piece of data as a element in a collection, i.e.: >> >> MyObjectStore("Column1").Value = DataRow("Column1") >> MyObjectStore("Column2").Value = DataRow("Column2") >> etc. > > Could you please be more specific as to how I must declare > MyObjectStore (what type): > Dim MyObjectStore As ???? > > and how to dimension MyObjectStore in order to accomodate all colums > in a given DataRow. http://samples.gotdotnet.com/quickstart/howto/doc/default.aspx Collections: Iterate over a collection? Use a Hashtable collection? Choose a collection to use? Implement a collection? Clone a collection? In particular, Hashtables could be used in your circumstance: http://samples.gotdotnet.com/quickstart/howto/doc/hashtable.aspx
Show quote
Hide quote
> Please read up on arrays, lists, and collections: I tried hashtable, sortedlist but I get following error:> > http://samples.gotdotnet.com/quickstart/howto/doc/default.aspx > > Collections: > Iterate over a collection? > Use a Hashtable collection? > Choose a collection to use? > Implement a collection? > Clone a collection? > > In particular, Hashtables could be used in your circumstance: > > http://samples.gotdotnet.com/quickstart/howto/doc/hashtable.aspx The type System.Collections.Hashtable is not supported because it implements IDictionary
Add custom button on title bar
Deleting blanks in a string Threading(?) & FileSystemWatcher fax question Sending Mail Show Msgbox in SYSTEM account adding xml data to a combobox Help.ShowPopup for all Textboxes on Form? Would like to see the Generated code in visual studio 2005 Check if string contain Uppercase. |
|||||||||||||||||||||||