Multicolumn UniqueConstraint in typed dataset/datatable - How to implement?

M

Marcus

I am trying to create a unique constraint for a typed datatable for
multiple columns so the same group of values will not appear more than
once for any one row (I can't make this group of columns a composite
primary key as one of the columns can sometimes be null). If I was
creating a non-typed dataset, then in the code it is quite simple to
implement this:

Dim dt As New DataTable("MyTable")

-- CODE TO DEFINE TABLE HERE ---

Dim myUniqueConstraint As UniqueConstraint
myUniqueConstraint = New UniqueConstraint(New DataColumn()
{dt.Columns("column1"), dt.Columns("column2"), dt.Columns("column3"),
dt.Columns("column4")})
dt.Constraints.Add(myUniqueConstraint)

However, I don't see how to do this for a typed dataset. I can select
all of the columns that I want in the dataset designer for the
datatable and assign the "unique" property to true, but the code that
it generates is individual unique constraints for each of the columns,
not a composite for all columns. Is there a way to set this in the
designer? Perhaps I can add the code in the partial class of the
dataset (I don't know how to do this...suggestions?). Is this possible
at all, or do I have to change my typed dataset, which only contains
one table, back into an untyped dataset?

Thanks,
Marcus
 
M

Marcus

Anybody? This seems to me to not be an unusual desire, to make a
multi-column Unique constraint on a typed dataset. Perhaps I am missing
something...

M.
 

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