How to prevent storing duplicate values

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,
 
M

Misbah Arefin

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;
 
M

Misbah Arefin

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,
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top