Wednesday, April 18, 2012

C#: Loop through DataRowView in DataView

It could be a bit different than looping through rows in DataTable, yet it's working just fine:



    public string[] get_Cities(string param)
    {

        DataView dv = new DataView((System.Data.DataTable)Application["cached_data_table"], "column_x = '" + param + "'", "sort_column", DataViewRowState.CurrentRows);

        foreach (DataRowView dr in dv)
        {
            list_cities.Add(dr["city_name"].ToString()); 
        }

        return list_cities.ToArray();



Enjoy!

No comments:

Post a Comment