OLE DB Insert 
Author Message
 OLE DB Insert

I am currently using the CTable template class with the "CDynamicAccessor"
accessor to insert records into a SQL Server 7 database. I am using the
CDynamicAccessor because I want the method that I am writing to work on a
number of tables.

The problem that I am having occurs when I try to insert some data into a
table which has a primary key. I have attached some example code to
illustrate what I am doing (notice the work around for the bug on the
"SetValue" method).

What is happening is that my attempts to create a blank row (not allowed for
tables with primary keys) which it will use to insert data into.

I would appreciate any advice on this matter.

Regards

Richard

P.S. Incidentally, does any one know of a good book or online resource which
has in depth descriptions and examples of how to use the Dynamic Accessors.



Tue, 05 Mar 2002 03:00:00 GMT  
 OLE DB Insert
    In OLE DB, Insert must contain a fully populated row (as opposed to ADO,
which uses the AddNew/.../Update construct). Alternatively, you could ask
for IRowsetUpdate as well as IRowsetChange, which would allow you to put in
a blank row, which you must update before writing it to the DBMS. You will
also need the property DBPROP_CHANGEINSERTEDROWS on the Rowset.
    You will also have problems if the primary key contains identity
columns, as CDynamicAccessor binds all the columns, and to the DBMS, you are
attempting to update an identity column. In this case you would have to
derive a class from CDynamicAccessor which does not bind the
identity column.
    Hope this is helpful,

Bob Beauchemin


Quote:
> I am currently using the CTable template class with the "CDynamicAccessor"
> accessor to insert records into a SQL Server 7 database. I am using the
> CDynamicAccessor because I want the method that I am writing to work on a
> number of tables.

> The problem that I am having occurs when I try to insert some data into a
> table which has a primary key. I have attached some example code to
> illustrate what I am doing (notice the work around for the bug on the
> "SetValue" method).

> What is happening is that my attempts to create a blank row (not allowed
for
> tables with primary keys) which it will use to insert data into.

> I would appreciate any advice on this matter.

> Regards

> Richard

> P.S. Incidentally, does any one know of a good book or online resource
which
> has in depth descriptions and examples of how to use the Dynamic
Accessors.



Wed, 06 Mar 2002 03:00:00 GMT  
 OLE DB Insert
Additionally, it appears as though CDynamicAccessor cannot write to an
empty table.  I have some sample code that will write a record to a
table as long as there is at least one record in the table.  If I try
to write to an empty table (such that a call to MoveFirst() or MoveLast
() fails), then the write also fails (0x80004005).  Could it be that
CDynamicAccessor sets up it's bindings on the first call to GetData()
(which is never called if there are no valid rows in the table)?  Does
anyone know how to get around this?

Thanks,
rick

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.



Sun, 10 Mar 2002 03:00:00 GMT  
 OLE DB Insert
    How are you getting the rowset on an empty table? Does it work with
CAccessor<UserRecordCls>?

Bob Beauchemin

Quote:

> Additionally, it appears as though CDynamicAccessor cannot write to an
> empty table.  I have some sample code that will write a record to a
> table as long as there is at least one record in the table.  If I try
> to write to an empty table (such that a call to MoveFirst() or MoveLast
> () fails), then the write also fails (0x80004005).  Could it be that
> CDynamicAccessor sets up it's bindings on the first call to GetData()
> (which is never called if there are no valid rows in the table)?  Does
> anyone know how to get around this?

> Thanks,
> rick

> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.



Sun, 10 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. insert : Multiple-step OLE DB operation generated errors

2. OLE DB consumer template - How to INSERT

3. Insert, Update, Delete of rows using OLE DB ATL Consumer Templates

4. OLE DB - ATL - The use of BOOKMARK cause error when try to Insert

5. OLE DB - ATL - The use of BOOKMARK cause error when try to Insert

6. Insert rows with OLE DB template?

7. OLE DB From VC++ 6.0 Delayed Update Problem on Insert

8. insert tables in ATL OLE DB Provider Templates

9. 0x80040E21 on INSERT (OLE DB & Oracle 8)

10. 0x80040E21 on INSERT (OLE DB & Oracle 8)

11. 0x80040E21 on INSERT (OLE DB & Oracle 8)

12. OLE DB Close DB Connection w/MSSQL 6.5

 

 
Powered by phpBB® Forum Software