Dataset Table in Array

J

John Reeve

How to put a list of rows from dataset table into an array ?

I tried with this code but it doesn't help.

ArrayList arrayList = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arrayList.Add (dr["Name"]);
}
 
G

Göran Andersson

John said:
How to put a list of rows from dataset table into an array ?

I tried with this code but it doesn't help.

ArrayList arrayList = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arrayList.Add (dr["Name"]);
}

I don't know exactly what you want, as your code does something
different from what you are asking for. This is closer to what you asked
for:

DataTable table = db.dataSetUsers.Tables["Functions"];
DataRow[] rows = new DataRow[table.Rows.Count];
int i = 0;
foreach (DataRow row in table.Rows) {
rows[i++] = row;
}
 
J

John Reeve

I want to add the names from database to an arraylist

--
Regards,
John Reeve


Göran Andersson said:
John said:
How to put a list of rows from dataset table into an array ?

I tried with this code but it doesn't help.

ArrayList arrayList = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arrayList.Add (dr["Name"]);
}

I don't know exactly what you want, as your code does something
different from what you are asking for. This is closer to what you asked
for:

DataTable table = db.dataSetUsers.Tables["Functions"];
DataRow[] rows = new DataRow[table.Rows.Count];
int i = 0;
foreach (DataRow row in table.Rows) {
rows[i++] = row;
}
 
G

Göran Andersson

John said:
I want to add the names from database to an arraylist

That's what your code is doing. In what way is it not helping?

Tip: If you are top posting, you should not have two dashes in your
signature. That is commonly regarded as end of message, so the news
reader removes everything below it. As you are top posting that means
the entire previous conversation.
 
I

Ignacio Machin ( .NET/ C# MVP )

I want to add the names from database to an arraylist

--
Regards,
John Reeve



Göran Andersson said:
John said:
How to put a list of rows from dataset table into an array ?
I tried with this code but it doesn't help.
ArrayList arrayList = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arrayList.Add (dr["Name"]);
}
I don't know exactly what you want, as your code does something
different from what you are asking for. This is closer to what you asked
for:
DataTable table = db.dataSetUsers.Tables["Functions"];
DataRow[] rows = new DataRow[table.Rows.Count];
int i = 0;
foreach (DataRow row in table.Rows) {
    rows[i++] = row;
}

- Show quoted text -

As what? as string?
List<string> names = new List<string>();
foreach (DataRow row in table.Rows) {
names.Add( row["FirstName"].ToString());
 
I

Ignacio Machin ( .NET/ C# MVP )

That's what your code is doing. In what way is it not helping?

Not really, the code just copy the ENTIRE column to an array, not very
useful IMHO.
 
G

Göran Andersson

Ignacio said:
Not really, the code just copy the ENTIRE column to an array, not very
useful IMHO.

That depends on what the OP wants to do, which is what I am trying to
find out...
 
R

Reeve

that works
thanks mudassar

--
Regards
Reeve - the developer

Mudassar Hassan said:
Try renaming the name of the arraylist; and it will works

ArrayList arr = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arr.Add (dr["Name"]);
}


Regards,
Mudassar Hassan
http://mudassarhassan.spaces.live.com/


Göran Andersson said:
That depends on what the OP wants to do, which is what I am trying to
find out...
 
G

Göran Andersson

Mudassar said:
Try renaming the name of the arraylist; and it will works

ArrayList arr = new ArrayList();
foreach (DataRow dr in db.dataSetUsers.Tables["Functions"].Rows)
{
arr.Add (dr["Name"]);
}


Regards,
Mudassar Hassan
http://mudassarhassan.spaces.live.com/

Why do you think that this would make any difference? Even if it may not
be ideal, the name arrayList is perfectly valid for an instance of the
class ArrayList.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top