none
Check for complete row match before inserting... RRS feed

  • Question

  • hi...

    I am using ACCESS 2007 database and C# in my application.

    I ave one table say 'myTable' in the database.
    This table has columns Sr.No.(int), DateTimeStamp(Date), Text(Memo) type.

    And in this table i am inserting the new data at regular intervals.

    How i can check whether the data which i am inserting is present in the table or not.
    I mean i want to check all the rows before inserting new data. If i found the match then i will not insert the new data.

    How i can do this...?


    Thanks in advance,
    IamHuM
    Sunday, February 14, 2010 11:50 AM

All replies

  • Hi,
    You can add a unique constraint on those columns using sql statements:

        ALTER TABLE myTable
        ADD CONSTRAINT UQ_myTable UNIQUE(Sr.No,DateTimeStamp,Text)


    and you will receive an exception when inserting duplicate rows to myTable.
    Sincerely,
    Eric
    Tuesday, February 16, 2010 10:19 AM
  • hi Eric ,

    Can I use unique index...? Is it what you are calling it as unique constraint...?

    Another thing is... can i get it without exception...like return value -1 or 0 for fail and 1 for success...?

    Thanks for the reply,
    IamHuM
    Wednesday, February 17, 2010 5:38 PM