OLEDB CAccessor with CMultipleResults what am I doing wrong.
-
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