G
Guest
Hi All
Does anyone know how can I select some column from a datatable
Chung
Does anyone know how can I select some column from a datatable
Chung
Chung said:Hi All,
Does anyone know how can I select some column from a datatable?
Chung
Chung said:Hi All
the DotNet framework, any fast function which can select some of the columnChung said:----- William Ryan eMVP wrote: -----
Hi Chung:
Chung said:Hi All,
What do you mean by Select? You can reference a column in a DataTable via
it's .Columns property ie myDataTable.Columns[0] would give you the first
column in the table, (Or you can reference it by name, so if column 0 was
named "User_Name") you could reference myDataTable.Columns["User_Name"];
Where possible, use the numeric index instead b/c it's a lot faster (for
instance, if you were iterating through 10000 rows you'd probably see a
notable performance difference). or you can use Bill Vaughn's cool method
and use an enum.
Now, if you are talking about a column in context of a row you could use
foreach(DataRow dro in myDataTable.Rows){
string s = (string)dro[0];
}
There is also a .Select method but I'm guessing that's not what you're
after.
Let me know if I didn't answer it and I'll do what I can.
HTH,
Bill
www.devbuzz.com
www.knowdotnet.com
Hi Bill,
Thank you for your quick respones.
I think I have to make my question more clear. What I mean is within
datarow which contains ID=10, but it will return all the datacolumn from theI know that we can use DataSet.Tables[0].Select("ID=10") to get all the