locked
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!

     

    jun2
     

    Tuesday, November 27, 2007 1:11 AM

All replies

  • User-587930081 posted

    Hi,

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

    DataRow.Table.Columns(0).ColumnName;



     

    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();

    Thanks

    -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

    thx

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

    Thanks

    It is very use full

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

    Hi,

    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