-
Mar 3rd, 2006, 12:46 PM
#1
Thread Starter
Addicted Member
[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:
'=================================================================================
' Open Connection to the left data source
'=================================================================================
Try
Dim dstSource As New DataSet
Dim dadHeader, dadItem As OleDbDataAdapter
Dim dtbHeader As New DataTable
Dim dtbItem As New DataTable
Dim strConn As String = Nothing
Dim strQuery As String = Nothing
strConn = gobjmodConnects.ConnectionString
gobjmodConnects.FileName = My.Computer.FileSystem.GetFileInfo(Me.txtFileImport.Text).Name
'=================================================================================
' Get the Invoice Header data and put it in a table called Headers
'=================================================================================
strQuery = gstrSQLqueryHeader.Replace("impFile.csv", gobjmodConnects.FileName)
strQuery = strQuery.Replace("{DocNo}", gobjmodConnects.CommandLineArguments)
If Get_OleData(dstSource, "Headers", strConn, strQuery) Then
' Set the Table names as variables
dtbHeader = dstSource.Tables("Headers")
' Set up PrimaryKeys
If Not Set_PrimaryKey(dtbHeader, "INV_REF") Then
Throw New Exception("Setting Header Primary Keys failed")
End If
Else
Throw New Exception("Retriving Header data failed")
End If
'=================================================================================
' Get the Invoice Item data and put it in a table called Items
'=================================================================================
strQuery = gstrSQLqueryHeader.Replace("impFile.csv", gobjmodConnects.FileName)
strQuery = strQuery.Replace("{DocNo}", gobjmodConnects.CommandLineArguments)
If Get_OleData(dstSource, "Item", strConn, strQuery) Then
' Set the Table names as variables
dtbItem = dstSource.Tables("Item")
' Set up PrimaryKeys
If Not Set_PrimaryKey(dtbItem, "ID") Then
Throw New Exception("Setting Items Primary Keys failed")
End If
Else
Throw New Exception("Retriving Items data failed")
End If
'=================================================================================
' Set the Relation between the header and items
'=================================================================================
If Not Set_Relations(dstSource, dtbHeader, dtbItem, "ID", "DocID", "relID") Then
Throw New Exception("Setting Header to Items Relation failed")
End If
Catch ex As Exception
'Create a Log event
Dim objLogEntry As New TXlog.TXLogEvent
objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
objLogEntry.Write()
Exit Sub
End Try
and the module
VB Code:
Imports System.Data.OleDb
Module modDataXchange
Friend Function Get_OleData(ByRef dtsSource As DataSet, _
ByVal strTable As String, _
ByVal strConn As String, _
ByVal strQuery As String) As Boolean
'=================================================================================
' Query to create table in dataset
'=================================================================================
Dim dtdTable As OleDbDataAdapter
Try
dtdTable = New OleDbDataAdapter(strQuery, strConn)
dtdTable.Fill(dtsSource, strTable)
Get_OleData = True
Catch ex As Exception
'Create a Log event
Dim objLogEntry As New TXlog.TXLogEvent
objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
objLogEntry.Write()
Get_OleData = False
End Try
End Function
Friend Function Set_Relations(ByRef dtsSource As DataSet, _
ByRef dttHeader As DataTable, _
ByRef dttItem As DataTable, _
ByVal strHeaderColumn As String, _
ByVal strItemColumn As String, _
ByVal strRelationName As String) As Boolean
'=================================================================================
' Setup Relations
' Create the Relationship (Between TRHeader and TRItem)
' We tell the relation to setup a Constraint to make sure the
' Relationship is created on a unique key
'=================================================================================
Try
dtsSource.Relations.Add(strRelationName, _
dttHeader.Columns(strHeaderColumn), _
dttItem.Columns(strItemColumn), True)
' Set the Relations to be nested
dtsSource.Relations(strRelationName).Nested = True
Set_Relations = True
Catch ex As Exception
'Create a Log event
Dim objLogEntry As New TXlog.TXLogEvent
objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
objLogEntry.Write()
Set_Relations = False
End Try
End Function
Friend Function Set_PrimaryKey(ByRef dttHeader As DataTable, _
ByVal strPrimaryKey As String) As Boolean
'=================================================================================
' Set up PrimaryKeys
'=================================================================================
Try
dttHeader.PrimaryKey = New DataColumn() {dttHeader.Columns(strPrimaryKey)}
Set_PrimaryKey = True
Catch ex As Exception
'Create a Log event
Dim objLogEntry As New TXlog.TXLogEvent
objLogEntry.Update(, EventLogEntryType.Information, ex.Message, , TXlog.TXLogEvent.LogCategory.None, ex.Source)
objLogEntry.Write()
Set_PrimaryKey = False
End Try
End Function
End Module
it is failing in the function Set_Relations on the line
VB Code:
dtsSource.Relations.Add(strRelationName, _
dttHeader.Columns(strHeaderColumn), _
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
-
Mar 3rd, 2006, 04:58 PM
#2
Fanatic Member
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.
-
Mar 3rd, 2006, 05:16 PM
#3
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|