dataset table into an array list

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
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 said:
arrayList.Add("myArrayList", dSet.Tables["MyTable"]);


Hrvoje Voda said:
How to put a specified dataset table into an array list ?

Hrcko
 
...
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
 
Functions is a name of the table in dataset.

So, when I user ArrayList.AddRange it's an error.
 
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
 
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
 
...
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.ColumnName;
// do something with the column name
}


// Bjorn 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 said:
...
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.ColumnName;
// do something with the column name
}


// Bjorn 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.

I don't understand what you mean here.

DataRows doesn't have names...

// Bjorn 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
 
...
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
 
I tried that,

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


Bjorn Abelli said:
...
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
 
Hrvoje Voda said:
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
 
Back
Top