Error in LINQ join

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    Error in LINQ join

    HI there,

    I am trying to join two datatables using LINQ.
    Code:
     Dim dt1 As New DataTable
                dt1.Load(dr1)
                Dim dt2 As New DataTable
                dt2.Load(dr2)
    
     Dim joinquery = From t1 In dt1.AsEnumerable(), t2 In dt2.AsEnumerable() _
                    Where (t1.Field(Of Long)("CLASS_N0") = _
                        t2.Field(Of Long)("CLASS_N0")) _
                    Select t1, t2
    NewDg.DataSource = joinquery
                NewDg.DataBind()
    When I debug this, I get the error, System.InvalidC astException: Specified cast is not valid.
    I get this error in the line, joinquery =...
    I also have used Integer as the field type for the column, CLASS_NO.
    can someone help me with this.

    I also tried using datarelation to join the two data tables, but could not figure how I can dispaly both parent table and child table in a single data gridview.

    thank you
    Last edited by user1980; Jun 29 '11, 07:47 PM. Reason: To add more details.
Working...