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

Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataSet'

4 Answers 660 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 08 Oct 2011, 04:09 PM
hi

I have this casting of dataset issues and i just could not get it working. please help and any inconvience caused regretted. Thanks

Unable to cast object of type 'System.Data.DataTable' to type 'System.Data.DataSet'.
 
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = "select" Then
Session("sessiondataset") = CType(Session("sessiondataset"), DataSet).Tables("CTETable").Select("Customer ='" + DirectCast(e.CommandSource, LinkButton).Text + "'")
 RadGrid1.Rebind()
end if
End Sub

Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = Session("sessiondataset")
 End Sub

 

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 10 Oct 2011, 04:08 AM
Hi L,

reviewing your code I find the following issue: First you are casting the Session("sessiondataset") object to DataSet. Then you are assigning it an object of time DataTable. So the second time the code is called the Session("sesiondataset") object holds a DataTable which you are trying to cast to DataSet and if that is the case, it is rather expected to receive the mentioned exception. I assume that you intended to use different Session object, like Session("sessiondataset") and Session("sessiondatable"), right?

Kind regards,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
L
Top achievements
Rank 1
answered on 10 Oct 2011, 02:28 PM
hi

I assume that you intended to use different Session object, like Session("sessiondataset") and Session("sessiondatable"), right?

No, I am not trying to use a different session object

As you can see from my code, i am trying to filter the data in the grid which is using session object in the RadGrid1_ItemCommand and NeedDataSource

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = "select" Then
Session("sessiondataset") = CType(Session("sessiondataset"), DataSet).Tables("CTETable").Select("Customer ='" + DirectCast(e.CommandSource, LinkButton).Text + "'")
 RadGrid1.Rebind()
end if
End Sub


 

 

Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

 RadGrid1.DataSource = Session("sessiondataset")

 

End Sub

 

I have looked through the examples on grid filtering but there isn't sample to show how to filter grid data when i am using session dataset in the grid.

Thanks and hope i am not giving you any inconveniences.
0
Iana Tsolova
Telerik team
answered on 10 Oct 2011, 03:09 PM
Hi L,

I see what you mean. However such approach cannot work as expected because you are using the same object for holding different types in it. You should either use different objects or move the code for filtering the DataSource in the NeedDataSource event.

All the best,
Iana Tsolova
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
L
Top achievements
Rank 1
answered on 11 Oct 2011, 03:33 PM
hi

Are there any example on how to filter data in the NeedDataSource method? thanks
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
L
Top achievements
Rank 1
Share this question
or