Help on How to Return DataRow's Column Name RRS feed

  • Question

  • User140238589 posted

     Can someone help me on how to return DataRow's column name? Like:

    Dim row as DataRow  = dt.Table(0).Row(0)

    MsgBox "Column: " & ColumnName & " Value: " & row("ColumnName")

    Where ColumnName is the table's column in the database.


    Thanks in advance!



    Tuesday, November 27, 2007 1:11 AM

All replies

  • User-587930081 posted


    Use the below code, you will get the column name. 



    Tuesday, November 27, 2007 1:29 AM
  • User445179017 posted

    To access the column names, use the Columns collection on datatable.

    DataTable dt = new DataTable();
    string colName = dt.Columns[0].ColumnName.ToString();
    string colValue = dt.Rows[0][0].ToString();


    -Mark post(s) as "Answer" that helped you

    Tuesday, November 27, 2007 1:30 AM
  • User140238589 posted

    Thanks guys! It really helped. 

    Tuesday, November 27, 2007 2:19 AM
  • User-1442337237 posted

    me too :P


    Wednesday, July 9, 2008 8:25 AM
  • User1374376170 posted


    It is very use full

    Wednesday, May 20, 2009 1:59 AM
  • User273921512 posted


    You can avoid loops, just need to check as below

    dtTableSorted.Columns.Contains("Col Name")

    dtTableSorted: datatable name

    Col Name: Column Name you want to check whether it exists in datatable

    Monday, December 13, 2010 9:41 AM