Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

table merge error

Status
Not open for further replies.

SavantMan

Programmer
Apr 17, 2002
165
US
I'm having difficulty with a function and can't find what the problem is. The code is below. Essentially, it works fine if the target table (tbl variable in code) is empty, however if it contains rows prior to the method being called, the error "'column' argument cannot be null" is thrown on the tbl.merge line. Any help would be greatly appreciated.

Code:
''' <summary>Imports data from the table passed in.</summary>
   ''' <returns>Number of successfully imported rows.  Returns 0 for error.</returns>
   Public Function AppendDataTable(ByVal SourceDataTable As DataTable) As Int32

      If SourceDataTable Is Nothing Then
         Return 0
      End If

      Try
         Dim ds As DataSet = DirectCast(mBindingSource.DataSource, DataSet)
         Dim tbl As DataTable = ds.Tables(mBindingSource.DataMember)
         tbl.Merge(SourceDataTable, True, MissingSchemaAction.Ignore) ' error is thrown by this line

         ' some other stuff happens here specific to my code, but removed for simplicity

         Return SourceDataTable.Rows.Count
      Catch ex As Exception
         Return 0
      End Try

   End Function
 
where do you set/prepare mBindingSource?

btw, you know you can use _BindingSouce instead of the VB6 mBindingSouce right? (Just Checking, don't shoot)



-The answer to your problem may not be the answer to your question.
 
Yes, I'm aware that the variable coule be named differently, no shooting necessary..:)

The class that AppendDataTable is part of is a wrapper --- mBindingSource is set in the contructor.
 
just for kicks, have you tried appending your mBindingSource to the SourceDatatable, you may have a problem with the columns not lining up.

-The answer to your problem may not be the answer to your question.
 
Something odd is happening here... I posted a response yesterday with the solution I found, and I had thought it had posted correctly. At any rate, here it is again:

There's more than one way to skin a cat. Since I'm not actually merging
here and just adding all records from one datatable to another, I've got a
different route.

Replacing:

Code:
   tbl.Merge(SourceDataTable, True, MissingSchemaAction.Ignore)

with:

Code:
For Each row As DataRow In SourceDataTable.Rows
   tbl.ImportRow(row)
Next

Handles things nicely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top