Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. OLEDB CAccessor with CMultipleResults what am I doing wrong.

OLEDB CAccessor with CMultipleResults what am I doing wrong.

Scheduled Pinned Locked Moved C / C++ / MFC
databasewpfwcfhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spawn Melmac
    wrote on last edited by
    #1

    The problem: I am using an accessor to INSERT into a table but this does return a value so I am using two commands to find out the ID of what was just inserted or at least that is the idea. I get DB_E_ERRORSINCOMMAND so if anyone can point me to where I am going wrong then you can save both my sanity and my hair... This is the accessor class from the test application I have been troubleshooting against.

    class CDBEvtRawInsert
    {
    public:
    // Data Elements
    int f_Direction;
    int f_HubID;
    TCHAR f_RawEvent[1400];
    LARGE_INTEGER f_RawEventID;

    BEGIN\_COLUMN\_MAP(CDBEvtRawInsert)
    	COLUMN\_ENTRY(1, f\_RawEventID)
    END\_COLUMN\_MAP()
    
    // Parameter binding map
    BEGIN\_PARAM\_MAP(CDBEvtRawInsert)
    	SET\_PARAM\_TYPE(DBPARAMIO\_INPUT)
    	COLUMN\_ENTRY(1, f\_Direction)
    	COLUMN\_ENTRY(2, f\_HubID)
    	COLUMN\_ENTRY(3, f\_RawEvent)
    END\_PARAM\_MAP()
    
    DEFINE\_COMMAND\_EX(CDBEvtRawInsert, L" \\
    						INSERT INTO \[RawEvent\] (\[TimeStamp\],\[Direction\],\[Hub\],\[RawEvent\])	\\
    						VALUES (GETDATE(),?,?,?);SELECT @@IDENTITY AS RawEventID")
    

    };

    This is an extract from the function

    CString szValue = \_T("test");
    HRESULT hr = E\_FAIL;
    CCommand<CAccessor<CDBEvtRawInsert >,CRowset, CMultipleResults > rsEvtRawInsert;
    
    wcscpy\_s(rsEvtRawInsert.f\_RawEvent, szValue.GetLength()\*2, szValue);
    rsEvtRawInsert.f\_Direction = 1;					
    rsEvtRawInsert.f\_HubID = 0;					
    hr = rsEvtRawInsert.Open(theApp.m\_oDB.session);			// <<==== fails here
    if(S\_OK == hr)
    {
    	DBROWCOUNT out;
    	hr = rsEvtRawInsert.GetNextResult(&out);
    

    I know the SQL is ok as I have tested it in SQL Management Studio on the same DB this code is using. Also if I make it a single recordset by removing the SELECT @@IDENTITY that works too. If you have an alternative suggestion which would achieve the same result then I am all ears. Thank you for reading this far.

    Alan

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups