How to prevent storing duplicate values

  • Thread starter Thread starter dotpro2008
  • Start date Start date
D

dotpro2008

In ASP.NET 2.0 project, I have added a dataset and have setup the datatable
and configured the datatableadapter (using the wizards).

In my code I can use the mytableadapter.insert method to insert a new record
in the table.

How do I check if the key column value being inserted this time already
exists and hence prompt the user the message ("userid already exists" or
"email address already exists")

Thanks,
 
You can use the DataTable.Select() method to search for the userid in the
datatable if it exists then show error message otherwise insert
another option would be to create a unique index on the userid column
DataTable.Columns["ColumnName"].Unique = true;
 
sorry to RE: on my own post but if your original intent was that the dattable
is empty and you are inserting a new row and wanted to check it against the
db rows then you would have to execute some SP which would seach the db table
for that value and return a scalar value indicating if the data exists or not

--
Misbah Arefin



Misbah Arefin said:
You can use the DataTable.Select() method to search for the userid in the
datatable if it exists then show error message otherwise insert
another option would be to create a unique index on the userid column
DataTable.Columns["ColumnName"].Unique = true;

--
Misbah Arefin



dotpro2008 said:
In ASP.NET 2.0 project, I have added a dataset and have setup the datatable
and configured the datatableadapter (using the wizards).

In my code I can use the mytableadapter.insert method to insert a new record
in the table.

How do I check if the key column value being inserted this time already
exists and hence prompt the user the message ("userid already exists" or
"email address already exists")

Thanks,
 
Back
Top