none
Cast conversion exception occurred RRS feed

  • Question

  • hello ,

    i am using LINQ TO SQL and my Project Saving data of employee

    and whern i Delete or search the saved data then it shows a cast convertion exception

    i search or delete the data of employees by filling the name of employee.

     

    following is the code for my delete button click event

     

     

      Try



                If namecombo.Text = "" Then
                    MessageBox.Show("Select the name to delete")
                End If


                'delete
                Dim db As New dbcontext
                Dim data = From tmp In db.tblbasic_infos Where tmp.ename = namecombo.Text Select tmp

                db.tblbasic_infos.DeleteOnSubmit(data)
                db.SubmitChanges()
                MessageBox.Show("Employee is deleted Successfully")
            Catch ex As Exception
                MessageBox.Show(ex.Message)

            End Try

     

     

    what is this cast convertion exception

    it does not occured all time for all names but occurss for certain names like it works when i fill "karan" {it may be any other, in my checking i fill this} it gives exception but when i fill 

    "taranjeet kaur" then it executes linq query and then again i fill "karan" then it executes .

    whats the problem with this........

     

     

    THE exception is:

    unable to cast object of type 'system.data.linq.dataquery'1[windowsapplication1.tblbasic_info]'to type 'windowsapplication1.tblbasic_info'.

     

    Tuesday, April 13, 2010 10:15 AM

Answers