R
Rob Oldfield
I'm trying to create a datatable with a primary key based on two datacolumns
(in fact, I'm getting the same error even if I just try a single column
key). I'm setting the table up with the code below (which appears to work
correctly), but when I then try to use the Find method on the table then I'm
getting told that it's failed because there's no primary key.
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.Decimal")
dc.ColumnName = "Value"
dtResult.Columns.Add(dc)
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "Code"
dtResult.Columns.Add(dc)
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "Date"
dtResult.Columns.Add(dc)
Dim PrimaryKeyColumns(1) As DataColumn
PrimaryKeyColumns(0) = dtResult.Columns("Code")
PrimaryKeyColumns(1) = dtResult.Columns("Date")
dtResult.PrimaryKey = PrimaryKeyColumns
Anyone have an idea where I'm going wrong?
(in fact, I'm getting the same error even if I just try a single column
key). I'm setting the table up with the code below (which appears to work
correctly), but when I then try to use the Find method on the table then I'm
getting told that it's failed because there's no primary key.
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.Decimal")
dc.ColumnName = "Value"
dtResult.Columns.Add(dc)
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "Code"
dtResult.Columns.Add(dc)
dc = New DataColumn()
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "Date"
dtResult.Columns.Add(dc)
Dim PrimaryKeyColumns(1) As DataColumn
PrimaryKeyColumns(0) = dtResult.Columns("Code")
PrimaryKeyColumns(1) = dtResult.Columns("Date")
dtResult.PrimaryKey = PrimaryKeyColumns
Anyone have an idea where I'm going wrong?