"Specified cast is not valid" error
I am getting the following error: "Specified cast is not valid"
----
Private Sub cmdCalcTotal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdCalcTotal.Click
Dim ds As DataSet
Try
ds = CType(dgrOrderDetails.DataSource, DataSet)
'Other code here to calculate the order total
Catch ex As Exception
MessageBox.Show(ex.Message, "Cannot set the dataset to the datagrid
datasource")
End Try
End Sub
----
Suggestions are greatly appreciated.
Re: "Specified cast is not valid" error
Have you assigned a DataSet object to the DataSource property of the grid in the first place? If you've assigned a DataTable or a BindingSource or something else then you cannot cast it as type DataSet.