Problem with binding Rad Grid using Microsoft Enterprise Library 5.0

6 posts, 1 answers
  1. Libertad
    Libertad avatar
    53 posts
    Member since:
    Sep 2008

    Posted 07 May 2010 Link to this post

    Hi There,
    I've upgrade my project to Microsoft Enterprise Library 5.0 (former version was 4.1) but I got a runtime error when the Rad Grid is binding.
    My code is something like below:

    public static IDataReader GetAllOrders()   
    {  
        SqlDatabase db = new SqlDatabase(connString);   
        return db.ExecuteReader("Orders_GetAll");   
    }  
     
    protected void Page_Load(object sender, EventArgs e)   
    {  
        shopGrid.DataSource = DataProvider.GetAllShopOrders();   
        shopGrid.DataBind();  
    }  
     

     

     

     

     

    End I get this error:
    Data source is an invalid type.  It must be either an IListSource, IEnumerable, or IDataSource.

    I didn't have this problem with Microsoft Enterprise Library 4.1 or lower.

     

     

     

     

  2. Answer
    Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 10 May 2010 Link to this post

    Hello Libertad,

    The issue you are facing is not related to our RadGrid control, but it is rooted in the IDataReader implementation returned by EntLib ExecuteReader method. The object (RefCountingDataReader) returned by the method is a wrapper over the actual IDataReader instance and does not implement none of the interfaces (IListSource, IEnumerable, or IDataSource) required by DataBoundControl. In order to verify this, you may try populating a MS GridView using the same approach.

    However, you can work around by using the inner reader instead, similar to the following:

    var innerReader = (reader as RefCountingDataReader).InnerReader;
    RadGrid1.DataSource = reader;
    RadGrid1.DataBind();

    Kind regards,
    Rosen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. marcelo perez
    marcelo perez avatar
    3 posts
    Member since:
    May 2010

    Posted 21 May 2010 Link to this post

    Hi Libertad have you found the way to fix the problem 'couse i have the same issue too with EntLib 5 here's my code

            Database db = DatabaseFactory.CreateDatabase("ConnectionString"); 
            protected void Page_Load(object sender, EventArgs e) 
            { 
                // Create the SQL query 
                string strSql = "select * from Usuario where ID_Usuario = 1"
     
                GridView1.DataSource = db.ExecuteReader(CommandType.Text, strSql); 
                GridView1.DataBind(); 
            } 

    and the runtime error when i try to bind the DataSource i get, is this:

    "Detalles de la excepción: System.InvalidOperationException: El origen de datos no es un tipo válido. Deber ser IListSource, IEnumerable o IDataSource."

     :( thanks in advance......
  5. marcelo perez
    marcelo perez avatar
    3 posts
    Member since:
    May 2010

    Posted 21 May 2010 Link to this post

    Hi Again... well  i apologize for not trying the first answer as good as I should do :( couse using that idea i think i've found my solution very bad looking je... but it seems to work... here is my code again:
     
            protected void Page_Load(object sender, EventArgs e) 
            { 
                // Create the SQL query 
                string strSql = "select * from Usuario where ID_Usuario = 1"
     
                using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) 
                { 
                    var innerReader = (reader as RefCountingDataReader).InnerReader; 
                    GridView1.DataSource = innerReader;//db.ExecuteReader(CommandType.Text, strSql); 
                    GridView1.DataBind(); 
                } 
            } 

    Best Regards.-
  6. Libertad
    Libertad avatar
    53 posts
    Member since:
    Sep 2008

    Posted 22 May 2010 Link to this post

    but I cannot solve it when I use the query in a data layer.
  7. marcelo perez
    marcelo perez avatar
    3 posts
    Member since:
    May 2010

    Posted 04 Jun 2010 Link to this post

    Well... I've been looking for that too but the nearest solution i´ve found es creating a class to convert the IDataReader object to a SQLDataReader with something like this:

    public class Convertir  
    {  
           public Convertir()  
        {  
        }  
           public SqlDataReader aDataSource(IDataReader data)  
           {  
               return (SqlDataReader)(((RefCountingDataReader)data).InnerReader);  
           }  
    and then fill a dataSource
    (i.e.

    oDropDownList.DataSource = GetRolesDS();
    oDropDownList.DataBind();

     

    ) with this method:

            public SqlDataReader GetRolesDS()  
            {  
                var Objetos = db.ExecuteReader("Rol_GetAll");  
                return oConvertir.aDataSource(Objetos);  
            } 

    I'm quite sure that there is a better way to do this but i can not find it, so... if anyone get here and read this bad code and like to help that would be very appreciated
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017