C++ Programming
09-17-2010, 03:52 AM
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 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); //<span class="code-comment">
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 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); //<span class="code-comment">