How to prevent storing duplicate values

Discussion in 'ASP .Net' started by dotpro2008, Feb 15, 2008.

  1. dotpro2008

    dotpro2008 Guest

    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,
    dotpro2008, Feb 15, 2008
    #1
    1. Advertising

  2. 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" wrote:

    > 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,
    >
    >
    >
    Misbah Arefin, Feb 15, 2008
    #2
    1. Advertising

  3. 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" wrote:

    > 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" wrote:
    >
    > > 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,
    > >
    > >
    > >
    Misbah Arefin, Feb 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Shane Fowlkes
    Replies:
    3
    Views:
    818
    =?Utf-8?B?QnJhZCBRdWlubg==?=
    Mar 10, 2005
  2. Replies:
    0
    Views:
    4,035
  3. pembed2003
    Replies:
    4
    Views:
    9,158
    pembed2003
    Apr 4, 2004
  4. YMPN
    Replies:
    3
    Views:
    1,149
  5. hummh
    Replies:
    0
    Views:
    339
    hummh
    Aug 9, 2007
Loading...

Share This Page