|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating an array of datarowsI put a bunch of datarows into a sorted list to sort them. Then I got an array of the sorted elements. However, I cannot typecast them. I get an invalid cast error. I notice that in the debugger, that arrays of datarows are listed as {Length=xx}, but my arrays are listed as {system.array} and refuse to typecast. Public Class mySortedList Inherits SortedList Public ReadOnly Property array() As Object Get Dim Result() As Object, X As Integer ReDim Result(Me.Count - 1) For X = 0 To Me.Count - 1 Result(X) = Me.GetByIndex(X) Next Return Result End Get End Property End Class Dim O As Object, TestRows() As DataRow O = EndRingsList.array ' OK to here TestRows = DirectCast(O, PressData.End_RingsRow()) ' Fails here O is listed in the debugger as {system.array} instead of {Length=xx} It sounds like I need to understand arrays better.
getchildrows(...) returns DataRow() and I can typecast it to a specific type of row array, but if I create my own function that returns DataRow(), I can't type cast it. Example: Dim Test1 as DataRow(), Test2 as pressdata.end_ringsRow() Test1=xx.GetChildRows("Relation") Test2=directcast(Test1, pressdata.end_ringsRow()) ' This works. Test1=myfunction() ' MyFunction returns type DataRow() Test2=directcast(Test1, Pressdata.end_ringsRow()) ' Gives an invalid cast error. I can get around this by creating a casting function for each type I need. I simply dimensions an array according to the number of elements in the source array and copies them all over and returns the result. How does the dataset class return DataRow() arrays that can be typecasted and my own functions can't? I would think that the DataSet (or DataTable) has schema information whereas
the Arraylist of datarows does not. Why are you not work with DataTables if you want to work with DataRows. You can sort datatables easier. -- Show quoteHide quoteDennis in Houston "creator_bob" wrote: > It sounds like I need to understand arrays better. > > getchildrows(...) returns DataRow() and I can typecast it to a specific > type of row array, but if I create my own function that returns > DataRow(), I can't type cast it. > > Example: > > Dim Test1 as DataRow(), Test2 as pressdata.end_ringsRow() > > Test1=xx.GetChildRows("Relation") > Test2=directcast(Test1, pressdata.end_ringsRow()) ' This works. > > Test1=myfunction() ' MyFunction returns type DataRow() > Test2=directcast(Test1, Pressdata.end_ringsRow()) ' Gives an invalid > cast error. > > I can get around this by creating a casting function for each type I > need. I simply dimensions an array according to the number of elements > in the source array and copies them all over and returns the result. > > How does the dataset class return DataRow() arrays that can be > typecasted and my own functions can't? > > Dennis wrote:
Show quoteHide quote > I would think that the DataSet (or DataTable) has schema information whereas My situation is I needed a sorted list of grandchildren, and my> the Arraylist of datarows does not. Why are you not work with DataTables if > you want to work with DataRows. You can sort datatables easier. > -- > Dennis in Houston > > > "creator_bob" wrote: > > > It sounds like I need to understand arrays better. > > > > getchildrows(...) returns DataRow() and I can typecast it to a specific > > type of row array, but if I create my own function that returns > > DataRow(), I can't type cast it. > > > > Example: > > > > Dim Test1 as DataRow(), Test2 as pressdata.end_ringsRow() > > > > Test1=xx.GetChildRows("Relation") > > Test2=directcast(Test1, pressdata.end_ringsRow()) ' This works. > > > > Test1=myfunction() ' MyFunction returns type DataRow() > > Test2=directcast(Test1, Pressdata.end_ringsRow()) ' Gives an invalid > > cast error. > > > > I can get around this by creating a casting function for each type I > > need. I simply dimensions an array according to the number of elements > > in the source array and copies them all over and returns the result. > > > > How does the dataset class return DataRow() arrays that can be > > typecasted and my own functions can't? > > > > grandchild table, even if it was sorted, wouldn't be sorted after getting all child rows; then with each of those child rows, getting its child row. I found the solution was to use the arraylist object. Then, when I am ready to return, I use ToArray(Element0.GetType). This returns an object that can be typecast. Working with arrays of datarows is quite customary, since a datarow can only belong to one datatable.
API Declarations...just curious.
CDec("") SNMP Setting the "Restore Down" Size How to get a KEY from a sorted list (not a VALUE) ?? problem in msgbox - reg Handling file/folder of too long path How To: C++ DLL function returns Structure Array to VB .NET Help needed with my program Help - Hours intervals problem |
|||||||||||||||||||||||