Results 1 to 2 of 2

Thread: "Specified cast is not valid" error

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    5

    "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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width