I have added unique constraint to datatable like this
DataTable dtemp
private void TempTable()
{
dtemp = new DataTable(\"Temp\");
dtemp.Columns.Add(new DataCo
Since you have define your constraint in the local DataTable, you're trying to catch the wrong type of exception. Instead of SqlException, a ConstraintException is thrown.
An immediate fix would be, to change the type of exception in your try clause:
try
{
dtemp.Rows.Add(mTable.TableID,mTable.Capacity);
}
catch (ConstraintException ee)
{
// handle the exception here
}
If you want to check your constraint in the database, then that's where you want to define it instead of in the DataTable. In this case, SqlException will get thrown, but only when you send the data to the database, not when you add a row to the DataTable.