473,770 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrays and dataset

I have a webservice that is returning a dataset. In dataset there is a table
with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
I then try to read only 2 of the columns into array (double[][]
valuesArray;) but i cant get it to work. It is LDepth and ServiceNumber.
Both columns has numbers with decimals. As a newbee i am struggling with
arrays :-)
Best regards
Trond
Nov 16 '05 #1
5 4672
Hi,

I don;t understand well your question, are you trying to create an array
with the components of two of the columns?
if so there is no way of doing it afaik, you would have to iterate in the
datarow collection.

now, regarding your target structure double[] [] maybe is not the best way
for store them. It seems more like a construction from C , what is what you
want?

Maybe the best for you is creating either a class or a struct with two
double components and then create an array with that, lie this:

struct MyStruct
{
double ldepth ;
double service;
MyStruct( double l, double s){ ldepth = l; service=s;}
}

MyStruct[] theArray;

//create it
theArray = new MyStruct[ theDataSet.Tabl es[0].Rows.Count ];
int i =0;
foreach( DataRow row in theDataSet.Tabl es[0].Rows )
{
theArray[ i++] = new MyStruct( Convert.ToDoubl e( row["XXX"]),
Convert.ToDoubl e( row["YYY"] );
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Trond" <tr***@montanis .com> wrote in message
news:Om******** ******@TK2MSFTN GP15.phx.gbl...
I have a webservice that is returning a dataset. In dataset there is a
table
with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
I then try to read only 2 of the columns into array (double[][]
valuesArray;) but i cant get it to work. It is LDepth and ServiceNumber.
Both columns has numbers with decimals. As a newbee i am struggling with
arrays :-)
Best regards
Trond

Nov 16 '05 #2
Yes I realize that I was a lil in the clouds in my post :-)
What I want is to create an array with values from one column in the
dataset. And then one more array with data from column2.
I was first thinking maybe I should create an jagged array, but I realize
that I don't have to do that. SO then my question is how can I get lets say
the third column into an array?. It is LDepth and the value of each row into
array.
If in database I have 500 rows I then want an array with 500 indexes holding
the values in LDepth :-)

Best regards
Trond

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:uH******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I don;t understand well your question, are you trying to create an array
with the components of two of the columns?
if so there is no way of doing it afaik, you would have to iterate in the
datarow collection.

now, regarding your target structure double[] [] maybe is not the best way for store them. It seems more like a construction from C , what is what you want?

Maybe the best for you is creating either a class or a struct with two
double components and then create an array with that, lie this:

struct MyStruct
{
double ldepth ;
double service;
MyStruct( double l, double s){ ldepth = l; service=s;}
}

MyStruct[] theArray;

//create it
theArray = new MyStruct[ theDataSet.Tabl es[0].Rows.Count ];
int i =0;
foreach( DataRow row in theDataSet.Tabl es[0].Rows )
{
theArray[ i++] = new MyStruct( Convert.ToDoubl e( row["XXX"]),
Convert.ToDoubl e( row["YYY"] );
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Trond" <tr***@montanis .com> wrote in message
news:Om******** ******@TK2MSFTN GP15.phx.gbl...
I have a webservice that is returning a dataset. In dataset there is a
table
with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
I then try to read only 2 of the columns into array (double[][]
valuesArray;) but i cant get it to work. It is LDepth and ServiceNumber.
Both columns has numbers with decimals. As a newbee i am struggling with
arrays :-)
Best regards
Trond


Nov 16 '05 #3
Try this;

string strSQL;
int index = 0;

string connString = "Server=(local) ;Initial Catalog=pubs;us er=sa;password= ";

SqlConnection conn = new SqlConnection(c onnString);

try

{

conn.Open();

strSQL = "SELECT * from authors";

SqlCommand cmd = new SqlCommand(strS QL,conn);

SqlDataAdapter da = new SqlDataAdapter( cmd);

DataSet ds = new DataSet();

da.Fill(ds);

int rowCount = ds.Tables[0].Rows.Count;

string[] names = new string[rowCount];

foreach(DataRow dr in ds.Tables[0].Rows)

{

names[index] = dr[0].ToString();

index++;

}

}

catch(Exception ex)

{

MessageBox.Show (ex.Message);

}

If you wish to use a multi-dimensional array, you will need to change the
loop to reflect the second dimension. I did not do that here as you
mentioned wanting seperate arrays.

For each column you want to insert into the array, merely change the index
value in dr[0] to the correct column number, remembering that the columns
are zero based.

--
Gerry O'Brien
Visual Basic.NET MVP
"Trond" <tr***@montanis .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Yes I realize that I was a lil in the clouds in my post :-)
What I want is to create an array with values from one column in the
dataset. And then one more array with data from column2.
I was first thinking maybe I should create an jagged array, but I realize
that I don't have to do that. SO then my question is how can I get lets
say
the third column into an array?. It is LDepth and the value of each row
into
array.
If in database I have 500 rows I then want an array with 500 indexes
holding
the values in LDepth :-)

Best regards
Trond

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote
in message news:uH******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I don;t understand well your question, are you trying to create an array
with the components of two of the columns?
if so there is no way of doing it afaik, you would have to iterate in
the
datarow collection.

now, regarding your target structure double[] [] maybe is not the best

way
for store them. It seems more like a construction from C , what is what

you
want?

Maybe the best for you is creating either a class or a struct with two
double components and then create an array with that, lie this:

struct MyStruct
{
double ldepth ;
double service;
MyStruct( double l, double s){ ldepth = l; service=s;}
}

MyStruct[] theArray;

//create it
theArray = new MyStruct[ theDataSet.Tabl es[0].Rows.Count ];
int i =0;
foreach( DataRow row in theDataSet.Tabl es[0].Rows )
{
theArray[ i++] = new MyStruct( Convert.ToDoubl e( row["XXX"]),
Convert.ToDoubl e( row["YYY"] );
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Trond" <tr***@montanis .com> wrote in message
news:Om******** ******@TK2MSFTN GP15.phx.gbl...
>I have a webservice that is returning a dataset. In dataset there is a
>table
> with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
> I then try to read only 2 of the columns into array (double[][]
> valuesArray;) but i cant get it to work. It is LDepth and
> ServiceNumber.
> Both columns has numbers with decimals. As a newbee i am struggling
> with
> arrays :-)
> Best regards
> Trond
>
>



Nov 16 '05 #4
Thanks a lot. That was it. Really appreciate that you took time to add code
to your reply.

It solved my problem :-)

Best regards

Trond

"Gerry O'Brien" <gk******@hotma il.com> wrote in message
news:Oj******** ******@tk2msftn gp13.phx.gbl...
Try this;

string strSQL;
int index = 0;

string connString = "Server=(local) ;Initial Catalog=pubs;us er=sa;password= ";
SqlConnection conn = new SqlConnection(c onnString);

try

{

conn.Open();

strSQL = "SELECT * from authors";

SqlCommand cmd = new SqlCommand(strS QL,conn);

SqlDataAdapter da = new SqlDataAdapter( cmd);

DataSet ds = new DataSet();

da.Fill(ds);

int rowCount = ds.Tables[0].Rows.Count;

string[] names = new string[rowCount];

foreach(DataRow dr in ds.Tables[0].Rows)

{

names[index] = dr[0].ToString();

index++;

}

}

catch(Exception ex)

{

MessageBox.Show (ex.Message);

}

If you wish to use a multi-dimensional array, you will need to change the
loop to reflect the second dimension. I did not do that here as you
mentioned wanting seperate arrays.

For each column you want to insert into the array, merely change the index
value in dr[0] to the correct column number, remembering that the columns
are zero based.

--
Gerry O'Brien
Visual Basic.NET MVP
"Trond" <tr***@montanis .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Yes I realize that I was a lil in the clouds in my post :-)
What I want is to create an array with values from one column in the
dataset. And then one more array with data from column2.
I was first thinking maybe I should create an jagged array, but I realize that I don't have to do that. SO then my question is how can I get lets
say
the third column into an array?. It is LDepth and the value of each row
into
array.
If in database I have 500 rows I then want an array with 500 indexes
holding
the values in LDepth :-)

Best regards
Trond

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote
in message news:uH******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I don;t understand well your question, are you trying to create an array with the components of two of the columns?
if so there is no way of doing it afaik, you would have to iterate in
the
datarow collection.

now, regarding your target structure double[] [] maybe is not the best

way
for store them. It seems more like a construction from C , what is what

you
want?

Maybe the best for you is creating either a class or a struct with two
double components and then create an array with that, lie this:

struct MyStruct
{
double ldepth ;
double service;
MyStruct( double l, double s){ ldepth = l; service=s;}
}

MyStruct[] theArray;

//create it
theArray = new MyStruct[ theDataSet.Tabl es[0].Rows.Count ];
int i =0;
foreach( DataRow row in theDataSet.Tabl es[0].Rows )
{
theArray[ i++] = new MyStruct( Convert.ToDoubl e( row["XXX"]),
Convert.ToDoubl e( row["YYY"] );
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Trond" <tr***@montanis .com> wrote in message
news:Om******** ******@TK2MSFTN GP15.phx.gbl...
>I have a webservice that is returning a dataset. In dataset there is a
>table
> with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
> I then try to read only 2 of the columns into array (double[][]
> valuesArray;) but i cant get it to work. It is LDepth and
> ServiceNumber.
> Both columns has numbers with decimals. As a newbee i am struggling
> with
> arrays :-)
> Best regards
> Trond
>
>



Nov 16 '05 #5
Glad it helped.

--
Gerry O'Brien
Visual Basic.NET MVP
"Trond" <tr***@montanis .com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Thanks a lot. That was it. Really appreciate that you took time to add
code
to your reply.

It solved my problem :-)

Best regards

Trond

"Gerry O'Brien" <gk******@hotma il.com> wrote in message
news:Oj******** ******@tk2msftn gp13.phx.gbl...
Try this;

string strSQL;
int index = 0;

string connString = "Server=(local) ;Initial

Catalog=pubs;us er=sa;password= ";

SqlConnection conn = new SqlConnection(c onnString);

try

{

conn.Open();

strSQL = "SELECT * from authors";

SqlCommand cmd = new SqlCommand(strS QL,conn);

SqlDataAdapter da = new SqlDataAdapter( cmd);

DataSet ds = new DataSet();

da.Fill(ds);

int rowCount = ds.Tables[0].Rows.Count;

string[] names = new string[rowCount];

foreach(DataRow dr in ds.Tables[0].Rows)

{

names[index] = dr[0].ToString();

index++;

}

}

catch(Exception ex)

{

MessageBox.Show (ex.Message);

}

If you wish to use a multi-dimensional array, you will need to change the
loop to reflect the second dimension. I did not do that here as you
mentioned wanting seperate arrays.

For each column you want to insert into the array, merely change the
index
value in dr[0] to the correct column number, remembering that the columns
are zero based.

--
Gerry O'Brien
Visual Basic.NET MVP
"Trond" <tr***@montanis .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> Yes I realize that I was a lil in the clouds in my post :-)
> What I want is to create an array with values from one column in the
> dataset. And then one more array with data from column2.
> I was first thinking maybe I should create an jagged array, but I realize > that I don't have to do that. SO then my question is how can I get lets
> say
> the third column into an array?. It is LDepth and the value of each row
> into
> array.
> If in database I have 500 rows I then want an array with 500 indexes
> holding
> the values in LDepth :-)
>
> Best regards
> Trond
>
> "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
> wrote
> in message news:uH******** ******@TK2MSFTN GP10.phx.gbl...
>> Hi,
>>
>> I don;t understand well your question, are you trying to create an array >> with the components of two of the columns?
>> if so there is no way of doing it afaik, you would have to iterate in
>> the
>> datarow collection.
>>
>> now, regarding your target structure double[] [] maybe is not the
>> best
> way
>> for store them. It seems more like a construction from C , what is
>> what
> you
>> want?
>>
>> Maybe the best for you is creating either a class or a struct with two
>> double components and then create an array with that, lie this:
>>
>> struct MyStruct
>> {
>> double ldepth ;
>> double service;
>> MyStruct( double l, double s){ ldepth = l; service=s;}
>> }
>>
>> MyStruct[] theArray;
>>
>> //create it
>> theArray = new MyStruct[ theDataSet.Tabl es[0].Rows.Count ];
>> int i =0;
>> foreach( DataRow row in theDataSet.Tabl es[0].Rows )
>> {
>> theArray[ i++] = new MyStruct( Convert.ToDoubl e( row["XXX"]),
>> Convert.ToDoubl e( row["YYY"] );
>> }
>>
>> Cheers,
>>
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>>
>> "Trond" <tr***@montanis .com> wrote in message
>> news:Om******** ******@TK2MSFTN GP15.phx.gbl...
>> >I have a webservice that is returning a dataset. In dataset there is
>> >a
>> >table
>> > with 4 columns. (LDate, LTime, LDepth and ServiceNumber)
>> > I then try to read only 2 of the columns into array (double[][]
>> > valuesArray;) but i cant get it to work. It is LDepth and
>> > ServiceNumber.
>> > Both columns has numbers with decimals. As a newbee i am struggling
>> > with
>> > arrays :-)
>> > Best regards
>> > Trond
>> >
>> >
>>
>>
>
>



Nov 16 '05 #6

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

Similar topics

6
1574
by: Bhavna | last post by:
Hi I am trying to use an array in my vb.net windows appliaction but i keep encountering an error This is what i have done so far I have declared 2 arrays and 1 varible (to keep track of the index position Public MyMealTypeArray() As Strin Public MyMealQtyArray() As Intege Public ArrayIndex As Integer =
2
7813
by: nitin8or | last post by:
Hi ALL, I want to display in a RichTextBox the Binary Large Objects data coming from database. If I have one record its not a problem I convert it to byte array and pass it on in a stream as a byte array and then call Loadfile method of RichTextBox and pass the stream. This works BUT IF I have more records I have to create a loop and some how pass the concatenated byte array and then pass it in a stream. I do this with
2
6227
by: Mike | last post by:
Hi! I am trying to determine if the DataRow of one dataset contains the same data as the DataRow of another. I figured I can extract ItemArray's from each dataset and then compare them. 1) Is this the fastest way? I will have to loop through thousands of rows for what I am doing. 2) How can I compare arrays for Value Equality ? I do not think array's ..Equal method does Value Equality check. Based on what I understood, it does...
2
1090
by: Islam Elkhayat | last post by:
here is my class public class AppointmentRowCollection : Appointment { public Appointment GetRowsCollection(out int rows) { int i = 0; dataset= new AppointmentDS(); dataset= SelectAppointment(); DataRowCollection drcollection = dataset.Appointments.Rows; rows = drcollection.Count;
2
2258
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So far, it works great (after having a bit of heartache about .Dispose() ). Now, I need a certain part of the class file to run through many times and
4
3011
by: simchajoy2000 | last post by:
Hi, I have a form containing a datagrid where users can enter in their specified information for each row and column. Behind the scenes I have a sub which handles datagrid.CurrentCellChanged because I need to be able to execute some code whenever a user clicks in a different cell of the datagrid. Inside this sub I place the datagrid.datasource into a data table so that I can work with it's contents. However, I am getting "Out of...
4
1993
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB contains the same items but not necessarily all the items. I need to know which items are missing. I remember messing with a compare array function but now I can't seem to find it anywhere. Ideas? I would rather NOT loop through each item in...
9
5357
by: Anil Gupte | last post by:
I am having a problem using Multidim arrays. I want to create an array which as I understand it is dimensioned as: dim xyz (rows,columns) as String I want to populate it with rows from a table in a database. I don't know how many rows I am getting so of course I have to Redim inside the loop that does this. Unfortunately, the error message and documentation say: "In a
1
4969
by: csgirlie | last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays. import os # for file handling functions import numpy as np # for array/matrix processing import matplotlib.pyplot as plt # for general plotting from mpl_toolkits.mplot3d import axes3d # for 3d plotting wordList= numFiles = 0 numDataSets = numVectors = sizeVector = 0
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.