Home All Groups Group Topic Archive Search About
Author
13 Dec 2006 6:36 PM
JT
Hi,
I am trying to simulate a join on two datatables using the merge method as
part of exploring a possible migration from CRXI reporting (where you can
report off of multi-table datasets) to SQL Reporting (where you cannot).  The
method below fails on the second merge call with a null reference exception -
object reference not set to instance of an object.  Can someone tell me why
and any workaround for it? 
Thanks


Private Sub MergeData()
        Try

            Dim dT As New DataTable
            dT.Merge(Me.DataSet1.Customers, True,
MissingSchemaAction.AddWithKey)

            dT.Merge(Me.DataSet1.Orders, True, MissingSchemaAction.AddWithKey)

            Me.DataGridView1.DataSource = dT
            Me.DataGridView1.Refresh()
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString)
        End Try
    End Sub
--
John

Author
14 Dec 2006 4:30 AM
JT
Never mind this question.  The null reference was the schema itself.  I think
this approach is a blind alley anyway.
--
John


Show quote
"JT" wrote:

> Hi,
> I am trying to simulate a join on two datatables using the merge method as
> part of exploring a possible migration from CRXI reporting (where you can
> report off of multi-table datasets) to SQL Reporting (where you cannot).  The
> method below fails on the second merge call with a null reference exception -
> object reference not set to instance of an object.  Can someone tell me why
> and any workaround for it? 
> Thanks
>
>
> Private Sub MergeData()
>         Try
>
>             Dim dT As New DataTable
>             dT.Merge(Me.DataSet1.Customers, True,
> MissingSchemaAction.AddWithKey)
>
>             dT.Merge(Me.DataSet1.Orders, True, MissingSchemaAction.AddWithKey)
>    
>             Me.DataGridView1.DataSource = dT
>             Me.DataGridView1.Refresh()
>         Catch ex As Exception
>             System.Windows.Forms.MessageBox.Show(ex.ToString)
>         End Try
>     End Sub
> --
> John
Author
14 Dec 2006 8:15 AM
WenYuan Wang
Hi John,

First of all, I'd like to confirm my understanding of your issue.
According to your description, I understand that you encountered some issue
when you use Datatable.merge() method.
If I misunderstand anything here, please don't hesitate to correct me.

In general, Null Reference Exception will occur when the object which you
use is null.
For this reason, at first , we would like to suggest you can check whether
the "Me.DataSet1.Orders" has been initialized before you merge it into dT.

If there is anything I can help with, please feel free to reply me here. We
will follow up.
I'm glad to work with you.
Sincerely,
Wen Yuan

AddThis Social Bookmark Button