473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating an array of datarows

How do I create an array of datarows from a sorted list?

I 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}

Sep 16 '06 #1
3 11444
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?

Sep 16 '06 #2
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.
--
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?

Sep 17 '06 #3

Dennis wrote:
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.
--
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?
My situation is I needed a sorted list of grandchildren, and my
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.

Sep 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Faheem Mitha | last post by:
Dear People, I have the current modest goal. Given a user defined class, I want to creata an array of instances of that class. Consider the following class. class cell: def...
6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
9
by: sci | last post by:
I believe both ways to create an array of strings are correct. Is there any difference between these two? 1. char *MyString = {"First string", "Second string", ..."Tenth string"}; 2. char...
1
by: Chris | last post by:
Hi, to create an array of 2 objects (e.g. of type '__gc class Airplane') I need to do : Airplane * arrAirplanes __gc = new Airplane* __gc; arrAirplanes = new Airplane("N12344"); arrAirplanes...
4
by: Rob Nicholson | last post by:
Consider the following example class: Public Class ExampleClass ReadOnly Property HelloWorld() As String Get Return "Hello, World" End Get End Property End Class
1
by: Andrew Poulos | last post by:
If I have an array whose elements may or may not also be arrays and I’m given a string that relates to an appropriate index in that array how do I use that string as the index? For example, if I...
1
by: osamutoglu | last post by:
Platform is VS.NET 2003 and i am trying to design an application with Forms What is wrong here i didnt get it.. is there something i am missing? .. .. ../** STRUCTURE PROTOTYPE **/ struct...
1
by: yankee1423 | last post by:
Hello all, I have 3 tables with 1 field in each. The third table has half a million rows in it so I can do this with excel. What I want to do is create an array that I can export to Excel. ...
7
by: anupamsps | last post by:
HI all, let me explain the problem: In my simulation I am using two class: particle and Container. //////////// the outline of particle class/////////////////////...
15
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.