473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Multidimensional ArrayList how to?

Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated from
an OleDbDataReader. Reason I'm using an ArrayList is I do not know the size
of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3

Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could talk
'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Many thanks and kind regards,
SpotNet
Nov 16 '05 #1
3 13696

"SpotNet" <Sp*****@msnews.grp> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated
from
an OleDbDataReader. Reason I'm using an ArrayList is I do not know the
size
of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3

Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could
talk
'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Out of curiosity, are you populating the ArrayList[] members? All you are
showing here is the creation of the array. ALl of its members will be null
until you explicitly instantiate them.

Nov 16 '05 #2

"SpotNet" <Sp*****@msnews.grp> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated from an OleDbDataReader. Reason I'm using an ArrayList is I do not know the size of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3 MD: Here you are just initializing arry not array members. It defines the
array parameters. it will not initialize each member ArrayList objects. So
due to Null, it will throw that exception.
You have to initialize each ArrayList members explicitly.
My Suggestion: Use another Collections member, to store ArrayList objects.
May be you can use ArrayList of ArrayList objects, may be it will be more
convenient. But it depends on your program logic.
Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could talk 'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Many thanks and kind regards,
SpotNet


HTH,
Mahesh Devjibhai Dhola
"Empower yourself...."
Nov 16 '05 #3
Thanks Daniel, I'm trying to populate the array

GetDataMatrix[0,0].Add(15); throws the exception, I've got the impression
that GetDataMatrix[0,0].Add(15) method, adds the int 15 (as an object) to
the array. Inferring form your response from the declaration,

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3];

I have to instantiate;
GetDataMatrix[0,0], GetDataMatrix[1,0], ...,GetDataMatrix[9,2] (in a loop of
course) and then assign them values?

Thanks again Daniel you've got me closer, I'll try it out...

Regards,
SpotNet
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...
:
: "SpotNet" <Sp*****@msnews.grp> wrote in message
: news:%2****************@TK2MSFTNGP15.phx.gbl...
: > Hi NewsGroup;
: >
: > Trying to construct a Multidimensional (2D more specifically) populated
: > from
: > an OleDbDataReader. Reason I'm using an ArrayList is I do not know the
: > size
: > of the first dimension (being rows), here's my final attempt below;
: >
: > System.Collections.ArrayList[,] GetDataMatrix = New
: > System.Collections.ArrayList[10, 3]; //Let's just say 10, 3
: >
: > Keeping it brief and simple excuse the syntax,
: >
: > GetDataMatrix[0,0].Add(15);
: >
: > Throws an exception right at me stating that, 'Object reference is not
an
: > instance of the object'. If only 'System.Collections.ArrayList' could
: > talk
: > 'cause I have a few hard words for it, well the multi-dimensional case
: > anyway. What am I doing wrong?
: >
:
: Out of curiosity, are you populating the ArrayList[] members? All you are
: showing here is the creation of the array. ALl of its members will be null
: until you explicitly instantiate them.
: >
:
:
Nov 16 '05 #4

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

Similar topics

1
by: Al Gorney | last post by:
How do you create a multidimensional array using ArrayList? I'm asking this because I can't have a static size except for the width. The length will continue to grow.
3
by: Naomi | last post by:
Hi there, Just wondering, if there is any way to have a dynamic / unspecified size of an array? It obviously needs to be updated, deleted etc. The only way I thought is by making the array...
2
by: Mike | last post by:
Hi, How can I declare and instantiate a multidimensional array that I need to return after having populated it from a DB. Here is the code: string g = new string; int i = 0; while(rdr.Read())...
1
by: davehunt | last post by:
Hi folks, New C# programmer here. I am reading some CSV data from a file into an ArrayList. I want to get the data from the ArrayList into a 2-dimensional array. I see a few references to...
3
by: Daves | last post by:
is it possible? if so - how would you do it?
2
by: d[ - - ]b | last post by:
Hi there, Just wondering, if there is any way to have a dynamic / unspecified size of an array? It obviously needs to be updated, deleted etc. The only way I thought is by making the array...
0
by: epigram | last post by:
Well, conceptually this is what I want to do. I was hoping to use an ArrayList to build a (dynamic) array of string arrays, and then bind the ArrayList object to a DataGrid. I can do that, but it...
1
by: RSH | last post by:
I have a situation where I need to use a multidimenstional Array in a dynamic environment. i need to be able to iterate through the loop easily and I dont know the dimensions so i was trying to...
2
by: Rob | last post by:
Hi, I want to create an arraylist of multidimension arrays. Currently I've managed to do these via conventional means as follows: Dim myarraylist As ArrayList = New ArrayList() Dim...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.