26 Mart 2011 Cumartesi

C# - convert DataTable to ArrayList

I need to output a result list which i have as DataTable from a C# web service. So, i have to convert it to ArrayList before using..
here is a code for conversion:
private ArrayList ConvertDT(ref DataTable dt) {
ArrayList converted = new ArrayList(dt.Rows.Count);

foreach (DataRow row in dt.Rows){
converted.Add(row);
}

return converted;
}

// for access
((DataRow)list[0])["startTime"].ToString()


1 yorum:

  1. very nice. Thanks.

    Take a look into this article http://www.etechpulse.com/2012/09/convert-datatable-to-json-in-aspnet.html

    YanıtlaSil