I need to relate two tables on four columns where one table is new and has no data (rows) yet. Here is the code I have so far where DS is the dataset containing the two tables, DA and DACom are the data adapters for the tables "Time" and "Comments", respectively:
DA.SelectCommand = New SqlCommand("Select * From vTimeTest", CN)
DA.Fill(DS, "Time")
CB.DataAdapter = DA
DACom.SelectCommand = New SqlCommand("Select * From TimeComments", CN)
DACom.Fill(DS, "Comments")
CBCom.DataAdapter = DACom
'Relate the TimeComments table to the Time table.
Dim ParentCols() As DataColumn = {DS.Tables("Time").Columns("JobID"), DS.Tables("Time").Columns("EmpID"),
DS.Tables("Time").Columns("MinRepDate"), DS.Tables("Time").Columns("MaxRepDate")}
Dim ChildCols() As DataColumn = {DS.Tables("Comments").Columns("JobID"), DS.Tables("Comments").Columns("EmpID"),
DS.Tables("Comments").Columns("MinRepDate"), DS.Tables("Comments").Columns("MaxRepDate")}
Dim ComRel As New DataRelation("RCom", ParentCols, ChildCols)
DS.Relations.Add(ComRel)
The next to the last code line triggers the error "column argument cannot be null". I'm assuming this error is triggered because the one table ("Comments") is new and has no data yet. Is there a way to relate a new table with no data to an existing table full of data? Should I join the two tables in the first line of code above instead of trying to create a relationship between the two tables?