Dataset Table in Array

  • Thread starter Thread starter John Reeve
  • Start date Start date
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"]);
}
 
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;
}
 
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;
}
 
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 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());
 
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.
 
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...
 
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...
 
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.
 
Back
Top