Constraints

G

Guest

Hi,

I would like to ad Constraints to a database column, which only can have
unique values. The column can be empty only if the table is empty (no
records).

Im using the syntaxt:
pk = new DataColumn[1];
pk[0] = ds.Tables["table"].Columns["ID"];
ds.Tables["table"].Constraints.Add(new UniqueConstraint("ConstrName", pk[0]));
ds.Tables["table"].PrimaryKey = pk;

The problem is when the datatable is empty. I get an error message "the
column doesn't contain the unique value".

Is it possible to avoid this with an empty table?

Thanks,
Lubomir
 
G

Guest

Lubomir said:
Hi,

I would like to ad Constraints to a database column, which only can have
unique values. The column can be empty only if the table is empty (no
records).

Im using the syntaxt:
pk = new DataColumn[1];
pk[0] = ds.Tables["table"].Columns["ID"];
ds.Tables["table"].Constraints.Add(new UniqueConstraint("ConstrName", pk[0]));
ds.Tables["table"].PrimaryKey = pk;

The problem is when the datatable is empty. I get an error message "the
column doesn't contain the unique value".

Is it possible to avoid this with an empty table?

Thanks,
Lubomir

Well, I've found and error already (a mistake in the table name when next
table was added to a dataset).
 

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