4
Cannot convert an object of type 'System.Collections.Generic.List in type 'System.Data.Dataset'?
After making a report query, I am storing the data in a list and showing the data on the screen, the more I have an option to export the data to the Excel, so not to repeat the query I am saving the data in a session.
Session
:
repeater_teste.DataSource = retorno;
Session["Ultimo_Relatorio"] = retorno
In the export option I am doing this way (generating error):
DataSet ds = (DataSet)Session["Ultimo_Relatorio"];
DataGrid dg = new DataGrid();
dg.AllowPaging = false;
dg.DataSource = ds.Tables[0];
dg.DataBind();
I found this article that said it was possible.
Doubt: why not simply set the list to Binding a Dataset?
– Jéf Bueno
@jbueno, show me how, put an example please
– Harry
Okay, there. Have a good time!
– Jéf Bueno
The article talks about storing the DS in Session and not cast from List to Dataset. By the error message it seems that the problem is cast. Supplement the question with the part of the code you store the DS in Session.
– Pagotti
@Pagotti, adjusted question. more complete
– Harry