UniqueConstraint

  • Thread starter Thread starter Alfred Gary Myers Jr.
  • Start date Start date
A

Alfred Gary Myers Jr.

Hi all,

I trying to make the code below work without success

Sub x()

Dim t As DataTable = New DataTable("t")

Dim c1 As DataColumn = New DataColumn("col1", GetType(String))

Dim c2 As DataColumn = New DataColumn("col2", GetType(String))

Dim c3 As DataColumn = New DataColumn("col3", GetType(String))

t.Columns.Add(c1)

t.Columns.Add(c2)

t.Columns.Add(c3)

Dim u As UniqueConstraint = New UniqueConstraint("u", New String()
{c1.ColumnName, c2.ColumnName}, True)

t.Constraints.Add(u)

End Sub



The problem is that if you inspect "u", it's properties aren't setted.

This is an overloaded constructor as documented in

help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemdataunique
constraintclassctortopic9.htm


I need this overload since it seems to be the only way I can create a
multi-column primary key in a DataTable on the Compact Framework, but it
can't get it to work either on the .NET Framework 1.1

Am I missing something?

Thanks in advance for any help provided.

Alfred Gary Myers Jr..
 
myTable.PrimaryKey = New DataColumn() {myTable.Columns("FirstField"), _
myTable.Columns("SecondField")}

This should work for you.

HTH,

Bill
 
Back
Top