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

Binding RadGrid to a SqlDataReader with multiple result sets

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
LACDA-IT
Top achievements
Rank 1
LACDA-IT asked on 08 Oct 2014, 04:57 PM
I have a stored procedure which returns multiple result sets. The code calls the procedure with ExecuteReader(CommandBehavior.CloseConnection), and then proceeds to fill several grids, as follows:

thisgrid.DataSource = dr
thisgrid.DataBind()
dr.NextResult()
thatgrid.DataSource = dr
thatgrid.DataBind()
dr.NextResult()
theothergrid.DataSource = dr
theothergrid.DataBind()
dr.NextResult()

Up until now, we've been using Infragistics grids. But now we're converting to Telerik, and I'm running into a problem. After the first grid is bound, the DataReader closes, and the call to NextResult() results in a "reader is closed" error.

So, my first question is, how do I tell the DataBind method, "Hey, don't close that connection - there are more result sets coming"?

I know that if I remove CommandBehavior.CloseConnection from the ExecuteReader command, the DataReader stays open, but then I'm left with an open connection. So my second question is, how do insure that the connection gets closed? Is it automatically closed when the DataReader closes?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 13 Oct 2014, 02:13 PM
Hello Grinnell,

Since RadGrid will work with the data that is provided to it, you can not specify how that data will be proceeded. When binding a grid by setting the DataSource property, the only condition is to set the DataSource property to an instance of the following types:
  • DataSet, DataTable, or DataView;
  • Array of DataRow;
  • Any object collection that implements the IListSource, IList, IEnumerable, or ICustomTypeDescriptor interface.

With the above clarification and due to the fact that RadGrid can not force the connection to stay open, the only thing that I can suggest is that you close your connection within the Page's PreRender event for example or in any other event that will fire after all grids are data bound. 

Hope this helps.



Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
LACDA-IT
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or