473,379 Members | 1,201 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,379 software developers and data experts.

Build a dynamic array from DataReader...

I'm having a hard time wrapping my head around how to build a
multi-dimensional array of n length out of a DataReader loop. Take this
pseudo-code:

=======================================
public string[,] get_array(string sql)
{

//create db connection & open

string[,] arrReturn = new String[,];

SqlDataReader dataReader = myCommand.ExecuteReader();

if (dataReader.HasRows)
{
while (dataReader.Read())
{
//next line I don't know what to do!
arrReturn.AddToArray = {dataReader[0].ToString(),
dataReader[1].ToString()};
}
}

myConn.Close();
return arrReturn;
}
========================================

I can't seem to find anything in my Google searches that relates to
this. ArrayList seems only to work for unidimensional arrays, while
Array.CreateInstance requires that I know the array size before
populating it (which a datareader can't give me).

I'd sure appreciate any help!

--Brent
Nov 19 '05 #1
1 3072
a jagged (array of arrays) might make more sense. easiest is an araylist of
string arrays.

//create db connection & open

ArrayList al = new ArrayList();

SqlDataReader dataReader = myCommand.ExecuteReader();

if (dataReader.HasRows)
{
while (dataReader.Read())
{
string[] fields = new string[datareader.FieldCount];
for (int i =0; i < datareader.FieldCount; ++i)
fields[i] = dataReader[i].ToString() ;
al .Add(fields);
}
}
string [][] arrReturn = (string[][]) al .ToArray(string[]);

//print
for (int row=0; row<arrReturn.Count; ++ row)
for (int col=0; col < arrReturn[row].Length; ++col)
print (arrReturn[row][col]);
-- bruce (sqlwork.com)


"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
I'm having a hard time wrapping my head around how to build a
multi-dimensional array of n length out of a DataReader loop. Take this
pseudo-code:

=======================================
public string[,] get_array(string sql)
{

//create db connection & open

string[,] arrReturn = new String[,];

SqlDataReader dataReader = myCommand.ExecuteReader();

if (dataReader.HasRows)
{
while (dataReader.Read())
{
//next line I don't know what to do!
arrReturn.AddToArray = {dataReader[0].ToString(),
dataReader[1].ToString()};
}
}

myConn.Close();
return arrReturn;
}
========================================

I can't seem to find anything in my Google searches that relates to this.
ArrayList seems only to work for unidimensional arrays, while
Array.CreateInstance requires that I know the array size before populating
it (which a datareader can't give me).

I'd sure appreciate any help!

--Brent

Nov 19 '05 #2

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

Similar topics

3
by: mudd | last post by:
How do I build Python so that I get static libraries instead of dynamic libraries (e.g. build/lib.solaris-2.8-sun4u-2.3/math.so)? John
1
by: Phillll Peeps via .NET 247 | last post by:
Hi there, hope you can help How can i put the contents of the clipboard into a two dimensional array of type double? i can get the data with: Dim iData As IDataObject = Clipboard.GetDataObject()...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
3
by: jagdishl | last post by:
Hi: I have to basically populate another dropdown list based on the first dropdown list.My first dropdown list contains only two values i.e 1.City 2.County So the second dropdownlist should...
1
by: | last post by:
I'm having a problem finding the cause for this problem. I have a solution in Visual Studio 2005 that contains two projects -- a Web Site and a Class Library. The web site references the class...
5
by: jimmy | last post by:
Hi, Does anyone know how to read the contents of a datareader into an array? The datareader will only hold one field called CuttingID. Can anyone help me including how i would declare the array...
2
by: =?Utf-8?B?ZGJhMTIz?= | last post by:
Note, I'm using C# I am wondering what type of control I should use for iterating through the set of records returned by callin this method below, so that I can then do some stuff with each...
2
by: Staj4 | last post by:
Hey, In our application, we need to build an array by selecting from a MS-SQL table. We want to process as follows: 1) Load the array with the SQL select statement 2) Process the array...
3
by: Hugh Oxford | last post by:
I want to build a string to reference an object. I can reference is manually thus: print_r($this->struct->parts->parts); but if I build a string... $string = "->parts->parts"
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
1
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...
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...

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.