CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Location
    maharashtra,india
    Posts
    12

    validating data to be inserted into database

    I want to insert data into the database(MS Access). While inserting I want to check whether the data to be inserted is already there in the database. If it is there then the data should not be inserted. I tried doing if rs.eof= true then rs.addnew. I am getting error in rs.addnew. The error is the operation requested cannot be performed. I think it is because the record pointer is pointing to the EOF. If I give rs.movelast I get the error recordset cannot move backwards.

    I would like to know how this problem can be solved.

    Thanks in anticipation,



  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: validating data to be inserted into database

    You could try setting a primary key to the field where you wish to check for duplicates. If a duplicate is added then a trappable error will be produced.

    One point to note though - you cannot set a primary key to a memo field, (> 255 chars)

    Andrew


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: validating data to be inserted into database

    First check what kind of cursor did you defined on your recordset. You might get this error if you have Forward only cursor. Define it as Dynamic cursor.

    In order to check if this record exists in the database, execute SQL before inserting the record.
    sSQL = "select * from Table where YourCondition"
    Your condition must define uniquuness of this record

    Open the recordset with this SQl and check if rs.RecordCount = 0 then insert your record

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: validating data to be inserted into database

    rs.eof= true then
    rs.edit
    rs.addnew
    ...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured