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

RE: Constraints by Lubomir

Lubomir
Mon Apr 04 21:53:01 CDT 2005

"Lubomir" wrote:

> 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).