Re: How can I get identify number after inserting
- From: <ZhPWan@xxxxxxxxx>
- Date: Tue, 14 Aug 2007 00:35:14 -0700
On 8 13 , 4 09 , <ZhP...@xxxxxxxxx> wrote:
Who can tell me how to get identify number after inserting?
In my application, a table create with Identify column.
After inserting, I need to get the number of the row.
I try to complete this function, but when excute the statement "", it
occurs an error.The error code is DB_E_ERRORSOCCURRED, the
prgBinding.pbBindExt show the error information :pExtension = CXX0030:
Error: unable to evaluate expression.
I code on WinCE platform using Visual C++, access the database with
oledb,The following is my fraction:
swprintf(szSQLText, L"INSERT INTO CALL_LOG(Direction, PhoneNumber,
StartTime, Duration) VALUES(%d, '%s', '%s', %d)",crRecord.direct,
crRecord.phoneNumber, crRecord.startTime, crRecord.duration);
XCHECK_HR( hr = ExecuteSQL(m_pICmdText, szSQLText) );
wcscpy(szSQLText, L"select @@IDENTITY " );
XCHECK_HR( hr = m_pICmdText->SetCommandText(DBGUID_SQL, szSQLText) );
XCHECK_HR( hr = m_pICmdText->Execute(NULL, IID_IRowset, NULL, NULL,
&pUnkRowset) );
XCHECK_HR(hr = pUnkRowset->QueryInterface( IID_IRowset,
(void**)&pIRowset));
//Get the Interface of Columns Info
XCHECK_HR( hr = pIRowset->QueryInterface(IID_IColumnsInfo, (void
**)&pIColumnsInfo) );
//Get the Column Info
XCHECK_HR( hr = pIColumnsInfo->GetColumnInfo(&ulNumCols,
&pDBColumnInfo, &pStringsBuffer) );
if( 0 == ulNumCols)
{
goto CLEANUP;}
dwBindingSize = 1;
prgBinding =
(DBBINDING*)CoTaskMemAlloc(sizeof(DBBINDING)*dwBindingSize);
if (NULL == prgBinding)
{
hr = E_OUTOFMEMORY;
goto CLEANUP;
}
// Set initial offset for binding position
//
dwOffset = 0;
prgBinding[0].iOrdinal = 0;
prgBinding[0].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;
prgBinding[0].obLength =
dwOffset;
prgBinding[0].obStatus = prgBinding[0].obLength + sizeof(ULONG);
prgBinding[0].obValue = prgBinding[0].obStatus + sizeof(DBSTATUS);
prgBinding[0].wType = pDBColumnInfo[0].wType;
prgBinding[0].pTypeInfo = NULL;
prgBinding[0].pObject = NULL;
prgBinding[0].pBindExt = NULL;
prgBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
prgBinding[0].dwFlags = 0;
prgBinding[0].bPrecision = pDBColumnInfo[0].bPrecision;
prgBinding[0].bScale = pDBColumnInfo[0].bScale;
prgBinding[0].cbMaxLen = pDBColumnInfo[0].ulColumnSize;
// Calculate the offset, and properly align it
//
dwOffset = prgBinding[0].obValue + prgBinding[0].cbMaxLen;
dwOffset = ROUND_UP(dwOffset, COLUMN_ALIGNVAL);
// Get IAccessor
//
XCHECK_HR( hr = pIRowset->QueryInterface(IID_IAccessor,
(void**)&pIAccessor) );
// Create the accessor
//
XCHECK_HR( hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA,
dwBindingSize, prgBinding, 0, &hAccessor, NULL) );
Today I try to analyse the result, I found that I make a mistake when
coding . This error statement is :
prgBinding[0].iOrdinal = 0;
When I make some change, the procedure go on
Thank everybody who care about this topic.
.
- References:
- Prev by Date: How can I get identify number after inserting
- Next by Date: Re: Connecting to Access 2007 on Vista 64 bit
- Previous by thread: How can I get identify number after inserting
- Next by thread: Re: Connecting to Access 2007 on Vista 64 bit
- Index(es):