By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

dataset table into an array list

P: n/a
How to put a specified dataset table into an array list ?

Hrcko
Nov 17 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
arrayList.Add("myArrayList", dSet.Tables["MyTable"]);
"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:d7**********@ss405.t-com.hr...
How to put a specified dataset table into an array list ?

Hrcko

Nov 17 '05 #2

P: n/a
I managed to fill an array, but I don't konw how to get a real informations
from that array.

When I try to fill a list with items from that array, I get:
System.Collections.ArrayList,
and not the actual data.

This is the code:

ArrayList arrayList = new ArrayList();
arrayList.Add (db.dataSetUsers.Functions);

list.Items.Add(arrayList);

Hrcko
"Adam Barker" <adam@NO******@q-state.co.NO_SPAM.uk> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
arrayList.Add("myArrayList", dSet.Tables["MyTable"]);
"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:d7**********@ss405.t-com.hr...
How to put a specified dataset table into an array list ?

Hrcko


Nov 17 '05 #3

P: n/a
"Hrvoje Voda" wrote...
I managed to fill an array, but I don't konw how to get
a real informations from that array.
It's a bit confusing when you're using the word "array" when you mean an
ArrayList (and v.v.)...
When I try to fill a list with items from that array,
I get: System.Collections.ArrayList, and not the actual data.
That is because you didn't "fill" the list with the actual items, but with
the ArrayList instance.

(I'm guessing that you really don't mean a "list", but a ListBox...)
list.Items.Add(arrayList);
I'm not even sure you've got the contents of the ArrayList right, as I guess
you "filled" it with some kind of collection of items, and not the items
themselves?
arrayList.Add (db.dataSetUsers.Functions);


So, what does the property "db.dataSetUsers.Functions" actually return?

If it's some collection implementing the interface ICollection, I guess you
rather want to use AddRange instead:

arrayList.AddRange (db.dataSetUsers.Functions);

....and similarily when you put the *contents* of the ArrayList into the
ListBox:

list.Items.AddRange( arrayList.ToArray() );

There's even a possibility that you could skip the intermediate step of
using the ArrayList, depending on what other use you have for it, and what
kind of collection "db.dataSetUsers.Functions" is.

Something like this should be possible:

list.Items.Add( db.dataSetUsers.Functions.ToArray() );

....but as I said, that's depending on which type of collection the Functions
property really is...
// Bjorn A
Nov 17 '05 #4

P: n/a
Functions is a name of the table in dataset.

So, when I user ArrayList.AddRange it's an error.
"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:OH**************@tk2msftngp13.phx.gbl...
"Hrvoje Voda" wrote...
I managed to fill an array, but I don't konw how to get
a real informations from that array.


It's a bit confusing when you're using the word "array" when you mean an
ArrayList (and v.v.)...
When I try to fill a list with items from that array,
I get: System.Collections.ArrayList, and not the actual data.


That is because you didn't "fill" the list with the actual items, but with
the ArrayList instance.

(I'm guessing that you really don't mean a "list", but a ListBox...)
list.Items.Add(arrayList);


I'm not even sure you've got the contents of the ArrayList right, as I
guess you "filled" it with some kind of collection of items, and not the
items themselves?
arrayList.Add (db.dataSetUsers.Functions);


So, what does the property "db.dataSetUsers.Functions" actually return?

If it's some collection implementing the interface ICollection, I guess
you rather want to use AddRange instead:

arrayList.AddRange (db.dataSetUsers.Functions);

...and similarily when you put the *contents* of the ArrayList into the
ListBox:

list.Items.AddRange( arrayList.ToArray() );

There's even a possibility that you could skip the intermediate step of
using the ArrayList, depending on what other use you have for it, and what
kind of collection "db.dataSetUsers.Functions" is.

Something like this should be possible:

list.Items.Add( db.dataSetUsers.Functions.ToArray() );

...but as I said, that's depending on which type of collection the
Functions property really is...
// Bjorn A

Nov 17 '05 #5

P: n/a

"Hrvoje Voda" wrote...
Functions is a name of the table in dataset.

So, when I user ArrayList.AddRange it's an error.
Of course it does, as DataTable doesn't implement ICollection.

From your sparse comments one couldn't tell if the data from the table
already was "transformed" or "converted" in some way to a collection,
reachable from the property db.dataSetUsers.Functions...

So what you're saying is that db.dataSetUsers.Functions returns a DataTable?

You still haven't said if you wanted the table as one single item in the
ArrayList, or if you wanted the rows from the table to appear as items in
the ArrayList...

If you want the table juat as a single item, you can still use the
"Add"-method (though it doesn't make much sense), but if you want the rows
as separate items, you will most likely need to iterate through the table,
and "Add" each item, e.g.

foreach (DataRow dr in db.dataSetUsers.Functions.Rows)
{
// Form the row into something suitable
// to be used in the ArrayList and/or ListBox
// and add it...
}
// Bjorn A

"Bjorn Abelli" wrote...
"Hrvoje Voda" wrote...
I managed to fill an array, but I don't konw how to get
a real informations from that array.


It's a bit confusing when you're using the word "array" when you mean an
ArrayList (and v.v.)...
When I try to fill a list with items from that array,
I get: System.Collections.ArrayList, and not the actual data.


That is because you didn't "fill" the list with the actual items, but
with the ArrayList instance.

(I'm guessing that you really don't mean a "list", but a ListBox...)
list.Items.Add(arrayList);


I'm not even sure you've got the contents of the ArrayList right, as I
guess you "filled" it with some kind of collection of items, and not the
items themselves?
arrayList.Add (db.dataSetUsers.Functions);


So, what does the property "db.dataSetUsers.Functions" actually return?

If it's some collection implementing the interface ICollection, I guess
you rather want to use AddRange instead:

arrayList.AddRange (db.dataSetUsers.Functions);

...and similarily when you put the *contents* of the ArrayList into the
ListBox:

list.Items.AddRange( arrayList.ToArray() );

There's even a possibility that you could skip the intermediate step of
using the ArrayList, depending on what other use you have for it, and
what kind of collection "db.dataSetUsers.Functions" is.

Something like this should be possible:

list.Items.Add( db.dataSetUsers.Functions.ToArray() );

...but as I said, that's depending on which type of collection the
Functions property really is...
// Bjorn A


Nov 17 '05 #6

P: n/a
I tried to put all that I could remember into
foreach()
{
...
}

but I just can't find a code that will put a column names into an ArrayList.

Hrcko
"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:ON***************@tk2msftngp13.phx.gbl...

"Hrvoje Voda" wrote...
Functions is a name of the table in dataset.

So, when I user ArrayList.AddRange it's an error.


Of course it does, as DataTable doesn't implement ICollection.

From your sparse comments one couldn't tell if the data from the table
already was "transformed" or "converted" in some way to a collection,
reachable from the property db.dataSetUsers.Functions...

So what you're saying is that db.dataSetUsers.Functions returns a
DataTable?

You still haven't said if you wanted the table as one single item in the
ArrayList, or if you wanted the rows from the table to appear as items in
the ArrayList...

If you want the table juat as a single item, you can still use the
"Add"-method (though it doesn't make much sense), but if you want the rows
as separate items, you will most likely need to iterate through the table,
and "Add" each item, e.g.

foreach (DataRow dr in db.dataSetUsers.Functions.Rows)
{
// Form the row into something suitable
// to be used in the ArrayList and/or ListBox
// and add it...
}
// Bjorn A

"Bjorn Abelli" wrote...
"Hrvoje Voda" wrote...

I managed to fill an array, but I don't konw how to get
a real informations from that array.

It's a bit confusing when you're using the word "array" when you mean an
ArrayList (and v.v.)...

When I try to fill a list with items from that array,
I get: System.Collections.ArrayList, and not the actual data.

That is because you didn't "fill" the list with the actual items, but
with the ArrayList instance.

(I'm guessing that you really don't mean a "list", but a ListBox...)

list.Items.Add(arrayList);

I'm not even sure you've got the contents of the ArrayList right, as I
guess you "filled" it with some kind of collection of items, and not the
items themselves?

arrayList.Add (db.dataSetUsers.Functions);

So, what does the property "db.dataSetUsers.Functions" actually return?

If it's some collection implementing the interface ICollection, I guess
you rather want to use AddRange instead:

arrayList.AddRange (db.dataSetUsers.Functions);

...and similarily when you put the *contents* of the ArrayList into the
ListBox:

list.Items.AddRange( arrayList.ToArray() );

There's even a possibility that you could skip the intermediate step of
using the ArrayList, depending on what other use you have for it, and
what kind of collection "db.dataSetUsers.Functions" is.

Something like this should be possible:

list.Items.Add( db.dataSetUsers.Functions.ToArray() );

...but as I said, that's depending on which type of collection the
Functions property really is...
// Bjorn A



Nov 17 '05 #7

P: n/a

"Hrvoje Voda" wrote...
I tried to put all that I could remember into
foreach()
{
...
}

but I just can't find a code that will put a
column names into an ArrayList.


If you want the column name from a specific column, you can get it through
its index, e.g.:

DataColumnCollection columns =
db.dataSetUsers.Functions.Columns;

for (int i = 0; i < columns.Count; i++)
{
string colname = columns[i].ColumnName;
// do something with the column name
}
// Bjorn A
Nov 17 '05 #8

P: n/a
Sorry, it's not column names but row names.
I tried to put DataRowCollection...
but I don't know how to get the row name.

Hrcko

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Hrvoje Voda" wrote...
I tried to put all that I could remember into
foreach()
{
...
}

but I just can't find a code that will put a
column names into an ArrayList.


If you want the column name from a specific column, you can get it through
its index, e.g.:

DataColumnCollection columns =
db.dataSetUsers.Functions.Columns;

for (int i = 0; i < columns.Count; i++)
{
string colname = columns[i].ColumnName;
// do something with the column name
}
// Bjorn A

Nov 17 '05 #9

P: n/a

"Hrvoje Voda" wrote...
Sorry, it's not column names but row names.
I tried to put DataRowCollection...
but I don't know how to get the row name.


I don't understand what you mean here.

DataRows doesn't have names...

// Bjorn A
Nov 17 '05 #10

P: n/a
I don't want to get the names of columns but of their rows.

For example: The name of the column is FunctionName,
but in the row is "Function for all".

Hrcko
"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP14.phx.gbl...

"Hrvoje Voda" wrote...
Sorry, it's not column names but row names.
I tried to put DataRowCollection...
but I don't know how to get the row name.


I don't understand what you mean here.

DataRows doesn't have names...

// Bjorn A

Nov 17 '05 #11

P: n/a

"Hrvoje Voda" wrote...
I don't want to get the names of columns but of their rows.

For example: The name of the column is FunctionName,
but in the row is "Function for all".


Let's see if I got this right...

So you *know* the column name...

You want the *content* of the column "FunctionName" from each row...

And then you want to add that to an ArrayList...

You could try this:

foreach (DataRow row in db.dataSetUsers.Functions.Rows)
{
string x = row["FunctionName"].ToString();
arrayList.Add ( x );
}
// Bjorn A
Nov 17 '05 #12

P: n/a
I tried that,

but when I fill a listbox with that arrayList I get :
System.Collection.ArrayList
"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:uI**************@TK2MSFTNGP10.phx.gbl...

"Hrvoje Voda" wrote...
I don't want to get the names of columns but of their rows.

For example: The name of the column is FunctionName,
but in the row is "Function for all".


Let's see if I got this right...

So you *know* the column name...

You want the *content* of the column "FunctionName" from each row...

And then you want to add that to an ArrayList...

You could try this:

foreach (DataRow row in db.dataSetUsers.Functions.Rows)
{
string x = row["FunctionName"].ToString();
arrayList.Add ( x );
}
// Bjorn A

Nov 17 '05 #13

P: n/a

"Hrvoje Voda" <hr*********@luatech.com> skrev i meddelandet
news:d7**********@ss405.t-com.hr...
I tried that,

but when I fill a listbox with that arrayList I get :
System.Collection.ArrayList


Then you missed what I said previously in this thread...

list.Items.AddRange(arraylist);
// Bjorn A
Nov 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.