[RESOLVED] Column argument cannot be null-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Column argument cannot be null

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    163

    Resolved [RESOLVED] Column argument cannot be null

    I am confused why I am getting the following error: 'Column arguement cannot be null' .
    Below is part of the form script calling three functions which are in module.
    VB Code:
    1. '=================================================================================
    2.         ' Open Connection to the left data source
    3.         '=================================================================================
    4.         Try
    5.             Dim dstSource As New DataSet
    6.             Dim dadHeader, dadItem As OleDbDataAdapter
    7.             Dim dtbHeader As New DataTable
    8.             Dim dtbItem As New DataTable
    9.             Dim strConn As String = Nothing
    10.             Dim strQuery As String = Nothing
    11.  
    12.             strConn = gobjmodConnects.ConnectionString
    13.             gobjmodConnects.FileName = My.Computer.FileSystem.GetFileInfo(Me.txtFileImport.Text).Name
    14.  
    15.             '=================================================================================
    16.             ' Get the Invoice Header data and put it in a table called Headers
    17.             '=================================================================================
    18.             strQuery = gstrSQLqueryHeader.Replace("impFile.csv", gobjmodConnects.FileName)
    19.             strQuery = strQuery.Replace("{DocNo}", gobjmodConnects.CommandLineArguments)
    20.             If Get_OleData(dstSource, "Headers", strConn, strQuery) Then
    21.                 ' Set the Table names as variables
    22.                 dtbHeader = dstSource.Tables("Headers")
    23.                 ' Set up PrimaryKeys
    24.                 If Not Set_PrimaryKey(dtbHeader, "INV_REF") Then
    25.                     Throw New Exception("Setting Header Primary Keys failed")
    26.                 End If
    27.             Else
    28.                 Throw New Exception("Retriving Header data failed")
    29.             End If
    30.  
    31.             '=================================================================================
    32.             ' Get the Invoice Item data and put it in a table called Items
    33.             '=================================================================================
    34.             strQuery = gstrSQLqueryHeader.Replace("impFile.csv", gobjmodConnects.FileName)
    35.             strQuery = strQuery.Replace("{DocNo}", gobjmodConnects.CommandLineArguments)
    36.             If Get_OleData(dstSource, "Item", strConn, strQuery) Then
    37.                 ' Set the Table names as variables
    38.                 dtbItem = dstSource.Tables("Item")
    39.                 ' Set up PrimaryKeys
    40.                 If Not Set_PrimaryKey(dtbItem, "ID") Then
    41.                     Throw New Exception("Setting Items Primary Keys failed")
    42.                 End If
    43.             Else
    44.                 Throw New Exception("Retriving Items data failed")
    45.             End If
    46.  
    47.             '=================================================================================
    48.             ' Set the Relation between the header and items
    49.             '=================================================================================
    50.             If Not Set_Relations(dstSource, dtbHeader, dtbItem, "ID", "DocID", "relID") Then
    51.                 Throw New Exception("Setting Header to Items Relation failed")
    52.             End If
    53.  
    54.         Catch ex As Exception
    55.             'Create a Log event
    56.             Dim objLogEntry As New TXlog.TXLogEvent
    57.             objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
    58.             objLogEntry.Write()
    59.             Exit Sub
    60.         End Try
    and the module
    VB Code:
    1. Imports System.Data.OleDb
    2.  
    3. Module modDataXchange
    4.     Friend Function Get_OleData(ByRef dtsSource As DataSet, _
    5.                                     ByVal strTable As String, _
    6.                                     ByVal strConn As String, _
    7.                                     ByVal strQuery As String) As Boolean
    8.         '=================================================================================
    9.         ' Query to create table in dataset
    10.         '=================================================================================
    11.         Dim dtdTable As OleDbDataAdapter
    12.         Try
    13.             dtdTable = New OleDbDataAdapter(strQuery, strConn)
    14.             dtdTable.Fill(dtsSource, strTable)
    15.             Get_OleData = True
    16.         Catch ex As Exception
    17.             'Create a Log event
    18.             Dim objLogEntry As New TXlog.TXLogEvent
    19.             objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
    20.             objLogEntry.Write()
    21.             Get_OleData = False
    22.         End Try
    23.     End Function
    24.     Friend Function Set_Relations(ByRef dtsSource As DataSet, _
    25.                                     ByRef dttHeader As DataTable, _
    26.                                     ByRef dttItem As DataTable, _
    27.                                     ByVal strHeaderColumn As String, _
    28.                                     ByVal strItemColumn As String, _
    29.                                     ByVal strRelationName As String) As Boolean
    30.         '=================================================================================
    31.         ' Setup Relations
    32.         ' Create the Relationship (Between TRHeader and TRItem)
    33.         ' We tell the relation to setup a Constraint to make sure the
    34.         ' Relationship is created on a unique key
    35.         '=================================================================================
    36.         Try
    37.             dtsSource.Relations.Add(strRelationName, _
    38.                                     dttHeader.Columns(strHeaderColumn), _
    39.                                     dttItem.Columns(strItemColumn), True)
    40.             ' Set the Relations to be nested
    41.             dtsSource.Relations(strRelationName).Nested = True
    42.             Set_Relations = True
    43.         Catch ex As Exception
    44.             'Create a Log event
    45.             Dim objLogEntry As New TXlog.TXLogEvent
    46.             objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
    47.             objLogEntry.Write()
    48.             Set_Relations = False
    49.         End Try
    50.     End Function
    51.     Friend Function Set_PrimaryKey(ByRef dttHeader As DataTable, _
    52.                                         ByVal strPrimaryKey As String) As Boolean
    53.         '=================================================================================
    54.         ' Set up PrimaryKeys
    55.         '=================================================================================
    56.         Try
    57.             dttHeader.PrimaryKey = New DataColumn() {dttHeader.Columns(strPrimaryKey)}
    58.             Set_PrimaryKey = True
    59.         Catch ex As Exception
    60.             'Create a Log event
    61.             Dim objLogEntry As New TXlog.TXLogEvent
    62.             objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
    63.             objLogEntry.Write()
    64.             Set_PrimaryKey = False
    65.         End Try
    66.     End Function
    67. End Module

    it is failing in the function Set_Relations on the line
    VB Code:
    1. dtsSource.Relations.Add(strRelationName, _
    2.                                     dttHeader.Columns(strHeaderColumn), _
    3.                                     dttItem.Columns(strItemColumn), True)

    any ideas ?

    PS. sorry that this is such a long post but I could not see how to show the whole problem without showing all the code
    chilling

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    749

    Re: Column argument cannot be null

    From looking at the code and reading the error message, it would appear to me that either the "ID" column does not exist in the dttHeader.Columns collection or the "DocID" column does not exist in the dttItem.Columns collection. When it is trying to get the specific column to use in the relationship, one of the accesses to the Columns collection is returning back a null.

    Try setting a breakpoint on the failing line and then highlight the dttHeader.Columns(strHeaderColumn) code and hit Shift-F9 and see what it evaluates to. Then try the same for the other DataTable. If one of them returns Null, then you have your answer as to why it is failing.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    163

    Re: Column argument cannot be null

    Thanks - found the error .... I was using the wrong SQLquery to get the item data, therefore it did not include the field I was trying to link to
    '=================================================================================
    ' Get the Invoice Item data and put it in a table called Items
    '=================================================================================
    strQuery = gstrSQLqueryHeader.Replace("impFile.csv", gobjmodConnects.FileName
    should have been
    'strQuery = gstrSQLqueryItem.Replace("impFile.csv", gobjmodConnects.FileName
    chilling

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.