I have added unique constraint to datatable like this
DataTable dtemp
private void TempTable()
{
dtemp = new DataTable(\"Temp\");
dtemp.Columns.Add(new DataCo
This is not a SQLException. Change your handling to be more specific around the exception. If you can't resolve that - change it to a regular Exception.
private void GetTable()
{
try
{
dtemp.Rows.Add(mTable.TableID,mTable.Capacity);
}
catch(Exception ee)
{
MessageBox.Show("Exception: " + ee.Message);
}
I would avoid using exceptions in this scenario. This is really a bad pattern. It is especially painful to debug when you have all exceptions turned on. A better practice is to check if the record exists, then add if it doesn't.
Think of exceptions as edge cases for unexpected events - not regular coding practices.