ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Converts a DataRow into a Hashtable.


/// <summary>
/// Converts a DataRow object into a Hashtable object, 
/// where the key is the ColumnName and the value is the row value.
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static Hashtable ToHashTable(this DataRow dr)
    Hashtable htReturn = new Hashtable(dr.ItemArray.Length);
    foreach (DataColumn dc in dr.Table.Columns)
        htReturn.Add(dc.ColumnName, dr[dc.ColumnName]);

    return htReturn;


Hashtable ht = myDataRow.ToHashTable();

Author: Jonnidip

Submitted on: 8 jun 2009

Language: C#

Type: System.Data.DataRow

Views: 6486