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[2,];
int i = 0;
while(rdr.Read())
{
g[0, i] = rdr.GetString(1) + " " + rdr.GetString(2);
g[1, i] = Convert.ToString(rdr.GetInt32(0)) + "~" +
rdr.GetString(3) + "~" +
rdr.GetString(4) + "~" +
rdr.GetString(5) + "~";
i++;
}
What is wrong with the above code? I try everything...
Thanks.
Mike 2 7551
Arrays declared with square brackets are fixed-sized, not dynamic in the way you're trying to treat it. Use an ArrayList to dynamically add the rows to the array and then convert it over to a fixed-size array. For example,
ArrayList ga = new ArrayList();
int i = 0;
while (rdr.Read())
{
string[] gi = new string[2];
gi[0] = rdr.GetString(1) + " " + rdr.GetString(2);
gi[1] = Convert.ToString(rdr.GetInt32(0)) + "~" +
rdr.GetString(3) + "~" +
rdr.GetString(4) + "~" +
rdr.GetString(5) + "~" };
ga.Add(gi);
}
string[][] g = (string[][]) ga.ToArray(typeof(string[]));
Ken
"Mike" <no****@nospam.com> wrote in message news:uQ*************@TK2MSFTNGP12.phx.gbl...
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[2,];
int i = 0;
while(rdr.Read())
{
g[0, i] = rdr.GetString(1) + " " + rdr.GetString(2);
g[1, i] = Convert.ToString(rdr.GetInt32(0)) + "~" +
rdr.GetString(3) + "~" +
rdr.GetString(4) + "~" +
rdr.GetString(5) + "~";
i++;
}
What is wrong with the above code? I try everything...
Thanks.
Mike
Thanks Ken.
"Ken Kolda" <ke*******@elliemae-nospamplease.com> wrote in message news:#f**************@TK2MSFTNGP10.phx.gbl...
Arrays declared with square brackets are fixed-sized, not dynamic in the way you're trying to treat it. Use an ArrayList to dynamically add the rows to the array and then convert it over to a fixed-size array. For example,
ArrayList ga = new ArrayList();
int i = 0;
while (rdr.Read())
{
string[] gi = new string[2];
gi[0] = rdr.GetString(1) + " " + rdr.GetString(2);
gi[1] = Convert.ToString(rdr.GetInt32(0)) + "~" +
rdr.GetString(3) + "~" +
rdr.GetString(4) + "~" +
rdr.GetString(5) + "~" };
ga.Add(gi);
}
string[][] g = (string[][]) ga.ToArray(typeof(string[]));
Ken
"Mike" <no****@nospam.com> wrote in message news:uQ*************@TK2MSFTNGP12.phx.gbl...
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[2,];
int i = 0;
while(rdr.Read())
{
g[0, i] = rdr.GetString(1) + " " + rdr.GetString(2);
g[1, i] = Convert.ToString(rdr.GetInt32(0)) + "~" +
rdr.GetString(3) + "~" +
rdr.GetString(4) + "~" +
rdr.GetString(5) + "~";
i++;
}
What is wrong with the above code? I try everything...
Thanks.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TLOlczyk |
last post by:
I have a brain cramp and I need some help.
I have a chunk of code below which demonstrates
a problem I have with multidimensional arrays.
I want to keep it simple but something specific is...
|
by: Charles Banas |
last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to
get some opinions and comments on it, hopefully so i can gain some
sort of insight as to why this works.
at the top of the...
|
by: Mark Smith |
last post by:
I'm trying to copy data from a 1D array to a 2D array.
The obvious thing doesn't work:
int twoDee = new int;
int oneDee = new int { 1, 2 };
Array.Copy(oneDee, 2, twoDee, 2, 2);
This causes a...
|
by: chris |
last post by:
Hi there,
I created a Multidimensional array of labels
Label lblMultiArray = new Label { {Label3, LblThuTotal},
{Label4,LblFriTotal} };
Now I would like to compare the values in the array,...
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to...
|
by: Chuy08 |
last post by:
If I have a multidimensional array like the following:
Array
$records =Array
0 = 30 year, 6.0;
1 = 30 year, 6.0;
2 = Pay Option, 1.0;
3 = Pay Option, 1.0;
How could I flatten this to...
|
by: LittleCake |
last post by:
Hi All,
I have a multidimensional array where each sub-array contains just two
entries, which indicates a relationship between those two entries. for
example the first sub-array:
=Array
(
=30...
|
by: Jezternz |
last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
|
by: filippo nanni |
last post by:
Hello everybody, my question is this:
I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code:
//BEGIN CODE
var...
|
by: Slain |
last post by:
I need to convert a an array to a multidimensional one. Since I need
to wrok with existing code, I need to modify a declaration which looks
like this
In the .h file
int *x;
in a initialize...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |