views:

18

answers:

1

I'm upgrading a .NET 2.0 site that uses Enterprise Library version 2 (DAAB mainly) to .NET version 3.5 and EntLib version 5. I've made the necessary changes and now I'm getting an error "The data source is of an invalid type. It must be an IListSource, IEnumerable or IDataSource". I'm getting this error trying to set the datasource of a DevExpress ASPxGridView control to an IDataReader.

Below is my code. Our app uses IDataReaders extensively....will these instances all need to be modified? I saw one article here that said to add .ToList() to the end of the data source but that is not a valid method in the IDataReader. Please note that while this particular file is C#, 99% of our app is coded in VB.NET.

private void GetRecentAddedCasesGridData()
    {
        dbReader = DAL.GetRecentAddedCases(iClientKey);
        if (dbReader != null)
        {
            GridRecentAddedCases.DataSource = dbReader;
            GridRecentAddedCases.DataBind();         
        }
        dbReader.Close();
        dbReader.Dispose();
        dbReader = null;
    }
+1  A: 

Try this extension method

public static IEnumerable<object[]> AsEnumerable(this IDataReader reader)
{
    while (reader.Read())
    {
        var ret = new object[reader.FieldCount];
        reader.GetValues(ret);
        yield return ret;
    }
}

Then you can write GridRecentAddedCases.DataSource = dbReader.AsEnumerable().

Noel Abrahams
Why is this change necessary??? Is it a .NET Framework 3.5 thing? Is it a DAAB 5 thing?
Mike