Re: MFC/ODBC/ACCESS Creating a New DataRecord in a table with primary key

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tim (Tim_at_NoSpam)
Date: 07/13/04


Date: Tue, 13 Jul 2004 13:19:58 +1200

Richard,

You need to look at the design of the table to get the answer.
The error message is quite informative - it is telling you that you have
violated a constraint - in this case either an index, primary key, or
relationsip.

>From what you have said, I would look first at the Identity column - you
cannot specify a value to go into an identity column under normal
circumstances.

- Tim

"Richard Rauch" <Richard.Rauch@vipa.de> wrote in message
news:eLNmxoAaEHA.3112@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I want to create a small MFC Programm for accessing a Microsoft Access
> Database.
> I have a table with an auto number field as primary key. From my
> MFC-Application i want to insert a new record. Doing this, i will get the
> following error message:
> "
> Error: failure updating record.
> The changes you requested to the table were not successful because they
> would cr
> eate duplicate values in the index, primary key, or relationship. Change
> the da
> ta in the field or fields that contain duplicate data, remove the index,
> or
> rede
> fine the index to permit duplicate entries and try again.
> State:23000,Native:-1605,Origin:[Microsoft][ODBC Microsoft Access Driver]
> "
> Im principle, I'm working with an example from the book "Inside Visual
> C++"
> The Source Code for Creating a new record:
>
> void CDevDBClientView::OnRecordAdd()
> {
> m_pSet->AddNew();
> UpdateData(TRUE);
> if ( m_pSet->CanUpdate() )
> {
> m_pSet->Update();
> }
> if ( !m_pSet->IsEOF() )
> {
> m_pSet->MoveLast();
> }
> UpdateData(FALSE);
> }
>
> Is there any possibility to get the new key from the database instead of
> creating an unique key from the program itself?
>
> Thanks
>
> Richard
>
>



Relevant Pages

  • Re: Duplicate the record in form and subform
    ... Have changed the code as below but got an error message "Error#3061, ... Dim strSql As String 'SQL statement. ... Dim lngID As String 'Primary key value of the new record. ... 'Make sure there is a record to duplicate. ...
    (microsoft.public.access.formscoding)
  • Re: No Duplicate Names
    ... I have a similar situation in a database and what I've done is institute a ... check to make sure there isn't a duplicate entry. ... >> single-field primary key to use as a foreign key in related tables. ... >> trying to develop is a complaint tracking system wherein a user could ...
    (microsoft.public.access.tablesdbdesign)
  • Re: removing last chrs (with different browsers giving different last chrs )
    ... I normally stick to regexp even if is_numericor type casting would also suffice, since the regexp engine is needed anyway, and I've set up a collection of frequently needed expressions as class constants. ... could very well be a primary key. ... In this case foreign key integrity would be violated (after all we are using a "real" relational database engine, ... A detailled error message is precisely the wrong thing in this case - it won't help the user, the developer has his or her own sources, but the evil bot will feast on that. ...
    (comp.lang.php)
  • Re: Duplicate entry inserted in the SQL database while calling an ASP
    ... By "duplicate", I am assuming you have a field or a combination of field ... this is one of the functions of a relational database: ... field or fields in a table and creating a unique index or primary key ... primary key or unique index" error. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Multiple Indexing
    ... to provide quick access to data not validate if duplicate records ... performance of your database. ... Or if these fields are the primary key ( ... > read and followed the steps on the help files for ...
    (microsoft.public.access.tablesdbdesign)