Hi
I have below data in Datatable . I want to save the value of colum header in a variable i.e LeadNumber.
foreach (DataRow colum in dt.Rows)
{
| LeadNumber | LeadSource |
| 1 | Email Marketing |
| 2 | Website |
Thanks
Hi
I have below data in Datatable . I want to save the value of colum header in a variable i.e LeadNumber.
foreach (DataRow colum in dt.Rows)
{
| LeadNumber | LeadSource |
| 1 | Email Marketing |
| 2 | Website |
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Apr 10, 2023, 3:34 AM
Hello Ramco,
You can access the value of the column header "LeadNumber" using the
Columnsproperty of theDataTableobject and then retrieve theColumnNameproperty of the correspondingDataColumnobject. Here's an example:This will give you the string "LeadNumber", assuming that the "LeadNumber" column is the first column in the
DataTable. You can replace the index 0 with the actual index of the row that contains the column headers.Thanks
Naimish Makwana
Jignesh KumarPosted Apr 8, 2023, 2:56 PM
Hello,
You can get column header using below code,
Above code will return all columns from your data table