This is a migrated thread and some comments may be shown as answers.

Problem with binding Rad Grid using Microsoft Enterprise Library 5.0

5 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Libertad
Top achievements
Rank 1
Libertad asked on 07 May 2010, 09:04 AM

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.

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 10 May 2010, 05:07 PM
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.
0
marcelo perez
Top achievements
Rank 1
answered on 21 May 2010, 03:15 PM
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......
0
marcelo perez
Top achievements
Rank 1
answered on 21 May 2010, 03:29 PM
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.-
0
Libertad
Top achievements
Rank 1
answered on 22 May 2010, 09:05 PM
but I cannot solve it when I use the query in a data layer.
0
marcelo perez
Top achievements
Rank 1
answered on 04 Jun 2010, 06:23 PM
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
Tags
Grid
Asked by
Libertad
Top achievements
Rank 1
Answers by
Rosen
Telerik team
marcelo perez
Top achievements
Rank 1
Libertad
Top achievements
Rank 1
Share this question
or