UniqueConstraint

  • Thread starter Alfred Gary Myers Jr.
  • 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..
 
W

William Ryan

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

This should work for you.

HTH,

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top