table merge error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt F

    #1

    table merge error

    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.



    ''' <summary>Import s data from the table passed in.</summary>

    ''' <returns>Numb er 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(mBin dingSource.Data Source, DataSet)

    Dim tbl As DataTable = ds.Tables(mBind ingSource.DataM ember)

    tbl.Merge(Sourc eDataTable, True, MissingSchemaAc tion.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


  • Matt F

    #2
    Re: table merge error

    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:

    tbl.Merge(Sourc eDataTable, True, MissingSchemaAc tion.Ignore)

    with:

    For Each row As DataRow In SourceDataTable .Rows
    tbl.ImportRow(r ow)
    Next

    Handles things nicely.


    Comment

    • Linda Liu [MSFT]

      #3
      Re: table merge error

      Hi Matt,

      I am curious about your problem : )

      I think the problem when you use the Merge method of DataTable may be
      caused by the schema of the current DataTable and the DataTable to be
      merged.

      You may have a try passing False for the second parameter in the Merge
      method, something like the following:

      tbl.Merge(Sourc eDataTable, False, MissingSchemaAc tion.Ignore)

      If the problem still exists, could you please send me a sample project that
      could reproduce the problem? To get my actual email address, remove
      'online' from my displayed email address.


      Sincerely,
      Linda Liu
      Microsoft Online Community Support

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      http://msdn.microsoft.com/subscripti...ult.aspx#notif
      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====

      This posting is provided "AS IS" with no warranties, and confers no rights.

      Comment

      • Matt F

        #4
        Re: table merge error

        Linda,

        Replacing the second parameter with "False" doesn't solve the issue. I've
        sent email per your request.

        "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.comwrote in message
        news:cnE20tSQHH A.4032@TK2MSFTN GHUB02.phx.gbl. ..
        Hi Matt,
        >
        I am curious about your problem : )
        >
        I think the problem when you use the Merge method of DataTable may be
        caused by the schema of the current DataTable and the DataTable to be
        merged.
        >
        You may have a try passing False for the second parameter in the Merge
        method, something like the following:
        >
        tbl.Merge(Sourc eDataTable, False, MissingSchemaAc tion.Ignore)
        >
        If the problem still exists, could you please send me a sample project
        that
        could reproduce the problem? To get my actual email address, remove
        'online' from my displayed email address.
        >
        >
        Sincerely,
        Linda Liu
        Microsoft Online Community Support
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/subscripti...ult.aspx#notif
        ications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====
        >
        This posting is provided "AS IS" with no warranties, and confers no
        rights.
        >

        Comment

        Working...