New to programming and got a question. I'm trying to add a primary key in vb.net to a table I made in SQL. The table in SQL does not have a primary key. I pull that table into my program and concatenate two columns and assign a series of numbers from a for loop to rows with nulls, to make a third column that is unique enough to be a primary key.
This is where i'm getting stuck. I'm trying to figure out how to assign a primary key in VB after i've pulled the data in from SQL.
Dim pkColumn(0) As DataColumn
pkColumn(0) = DS.Tables("CBOEOI").Columns("CompleteSymbol")
DS.Tables("CBOEOI").PrimaryKey() = pkColumn
adaptor.UpdateCommand = cmdBuilder.GetUpdateCommand()
adaptor.Update(DS.Tables("CBOEOI"))
If I run this I get
"{"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information."},
which indicates to me that the primary key wasn't set.
I've tried to set up isParentKey without much luck. I've done:
'test to determine if parent key was established
'datarelation = New DataRelation("CS", DS.Tables("CBOEOI").Columns("CompleteSymbol"), DS.Tables("CBOEOI").Columns("CompleteSymbol"), False)
'DS.Relations.Add(datarelation)
'datarelation = DS.Relations("CBOEOI")
'uconstraint = datarelation.ParentKeyConstraint
'If uconstraint.IsPrimaryKey Then
' MsgBox("CompleteSymbol is the primary key")
'Else
' MsgBox("doh")
'End If
But I can't figure out how to make it work without multiple tables. I get a both tables are the same error which is what I want since I only use one column for a key.
Any suggestions for how to resolve this would be greatly appreciated.