How to read back the value of the autonumber in Access database?



Hi

I have some problem using the OLEDB consumer template.
I actually want to insert a record into an Access table.
The table contains a field which is an autonumber.
My question is how to get back the value of the autonumber once the record
is inserted.
I am using Jet 4.0 provider.

Appreciate your help.


Regards
Tham


The following are the code snippet:

//****************************************************************
// binding class
//****************************************************************
class CMyDataAccessor
{
public:
CMyDataAccessor()
{
m_lID = 0;
m_szName[0] = NULL;
}

public:
LONG m_lID;
TCHAR m_szName[100];
LONG m_lID_status;

BEGIN_COLUMN_MAP(CMyDataAccessor)
COLUMN_ENTRY_STATUS(1, m_lID, m_lID_status);
COLUMN_ENTRY(2, m_szName);
END_COLUMN_MAP()
};

//**********************************************************************
// insert an record function
//**********************************************************************
HRESULT hr;
int nIndex = 0;
int nCount = 0;
CSession session;
CDBPropSet propset(DBPROPSET_ROWSET);
CTable<CAccessor<CMyDataAccessor>, CRowset> table;
CString str;

UpdateData(TRUE);

hr = session.Open(m_ds);
if( FAILED(hr) )
{
MessageBox(_T("Failed to open session"));
goto Exit;
}

propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
propset.AddProperty(DBPROP_IRowsetScroll, true);
propset.AddProperty(DBPROP_OWNINSERT, true);
propset.AddProperty(DBPROP_OWNUPDATEDELETE, true);
propset.AddProperty(DBPROP_OTHERINSERT, false);
propset.AddProperty(DBPROP_OTHERUPDATEDELETE, true);
propset.AddProperty(DBPROP_IRowsetChange, true);
propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
DBPROPVAL_UP_DELETE |
DBPROPVAL_UP_INSERT);
hr = table.Open(session, _T("mydata"), &propset);
if( FAILED(hr) )
{
MessageBox(_T("Failed to open table"));
goto Exit;
}

table.m_lID_status = DBSTATUS_S_DEFAULT;
lstrcpy(table.m_szName, m_strName);
hr = table.Insert();
if( FAILED(hr) )
{
MessageBox(_T("Failed to insert record"));
}
else
{
MessageBox(_T("Record inserted"));
}

Exit:
return;


.