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("CBOE OI").Columns("C ompleteSymbol")
DS.Tables("CBOE OI").PrimaryKey () = pkColumn
adaptor.UpdateC ommand = cmdBuilder.GetU pdateCommand()
adaptor.Update( DS.Tables("CBOE OI"))
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("C S", DS.Tables("CBOE OI").Columns("C ompleteSymbol") , DS.Tables("CBOE OI").Columns("C ompleteSymbol") , False)
'DS.Relations.A dd(datarelation )
'datarelation = DS.Relations("C BOEOI")
'uconstraint = datarelation.Pa rentKeyConstrai nt
'If uconstraint.IsP rimaryKey Then
' MsgBox("Complet eSymbol 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.
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("CBOE OI").Columns("C ompleteSymbol")
DS.Tables("CBOE OI").PrimaryKey () = pkColumn
adaptor.UpdateC ommand = cmdBuilder.GetU pdateCommand()
adaptor.Update( DS.Tables("CBOE OI"))
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("C S", DS.Tables("CBOE OI").Columns("C ompleteSymbol") , DS.Tables("CBOE OI").Columns("C ompleteSymbol") , False)
'DS.Relations.A dd(datarelation )
'datarelation = DS.Relations("C BOEOI")
'uconstraint = datarelation.Pa rentKeyConstrai nt
'If uconstraint.IsP rimaryKey Then
' MsgBox("Complet eSymbol 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.
Comment