当前位置: 代码迷 >> Windows Mobile >> northwindoledb相关有关问题
  详细解决方案

northwindoledb相关有关问题

热度:78   发布时间:2016-04-25 07:43:16.0
northwindoledb相关问题
HRESULT hr = NOERROR; DBBINDING *prgBinding = NULL; HROW rghRows[1]; HROW *prghRows = rghRows; DBID TableID; DBID IndexID; DBPROPSET rowsetpropset[1]; DBPROP rowsetprop[1]; ULONG cRowsObtained = 0; DBOBJECT dbObject; DBCOLUMNINFO *pDBColumnInfo = NULL; BYTE *pData = NULL; WCHAR *pStringsBuffer = NULL;
DWORD dwBindingSize = 0;
DWORD dwIndex = 0;
DWORD dwOffset = 0;
DWORD dwOrdinal = 0;
ULONG ulNumCols;
IOpenRowset *pIOpenRowset = NULL; // Provider Interface Pointer
IRowset *pIRowset = NULL; // Provider Interface Pointer
IRowsetIndex *pIRowsetIndex = NULL; // Provider Interface Pointer
IAccessor *pIAccessor = NULL; // Provider Interface Pointer
ILockBytes *pILockBytes = NULL; // Provider Interface Pointer
IColumnsInfo *pIColumnsInfo = NULL; // Provider Interface Pointer
HACCESSOR hAccessor = DB_NULL_HACCESSOR;// Accessor handle

WCHAR* pwszEmployees[] = { // Employee info Column names
L"Name",
L"No",
L"X",
L"Y",  
L"Z", 
L"P"
};
/*CREATE TABLE Step(Name NVARCHAR(20),No NVARCHAR(20),X NVARCHAR(20),Y NVARCHAR(20),Z NVARCHAR(20),P NVARCHAR(20),与数据库对应的columnm名字*/
VariantInit(&rowsetprop[0].vValue);

// Validate IDBCreateSession interface
//
if (NULL == m_pIDBCreateSession)
{
hr = E_POINTER;
goto Exit;
}

// Create a session object 
//
hr = m_pIDBCreateSession->CreateSession(NULL, IID_IOpenRowset, (IUnknown**) &pIOpenRowset);
if(FAILED(hr))
{
goto Exit;
}

// Set up information necessary to open a table 
// using an index and have the ability to seek.
//
TableID.eKind = DBKIND_NAME;
TableID.uName.pwszName = (WCHAR*)L"Step";

IndexID.eKind = DBKIND_NAME;
IndexID.uName.pwszName = L"I_Step";

// Request ability to use IRowsetChange interface
// 
rowsetpropset[0].cProperties = 1;
rowsetpropset[0].guidPropertySet= DBPROPSET_ROWSET;
rowsetpropset[0].rgProperties = rowsetprop;

rowsetprop[0].dwPropertyID = DBPROP_IRowsetIndex;
rowsetprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
rowsetprop[0].colid = DB_NULLID;
rowsetprop[0].vValue.vt = VT_BOOL;
rowsetprop[0].vValue.boolVal = VARIANT_TRUE;

// Open the table using the index
//
hr = pIOpenRowset->OpenRowset( NULL,
&TableID,
&IndexID,
IID_IRowsetIndex,
sizeof(rowsetpropset)/sizeof(rowsetpropset[0]),
rowsetpropset,
(IUnknown**) &pIRowsetIndex);
if(FAILED(hr))
{
goto Exit;
}

// Get IRowset interface
//
hr = pIRowsetIndex->QueryInterface(IID_IRowset, (void**) &pIRowset);
if(FAILED(hr))
{
goto Exit;
}

// Get IColumnsInfo interface
//
hr = pIRowset->QueryInterface(IID_IColumnsInfo, (void **)&pIColumnsInfo);
if(FAILED(hr))
{
goto Exit;
}

// Get the column metadata 
//
hr = pIColumnsInfo->GetColumnInfo(&ulNumCols, &pDBColumnInfo, &pStringsBuffer);
if(FAILED(hr) || 0 == ulNumCols)
{
goto Exit;
}

// Create a DBBINDING array.
//
dwBindingSize = sizeof(pwszEmployees)/sizeof(pwszEmployees[0]);
prgBinding = (DBBINDING*)CoTaskMemAlloc(sizeof(DBBINDING)*dwBindingSize);
if (NULL == prgBinding)
{
hr = E_OUTOFMEMORY;
goto Exit;
}

// Set initial offset for binding position
//
dwOffset = 0;

// Prepare structures to create the accessor
//
for (dwIndex = 0; dwIndex < dwBindingSize; ++dwIndex)
  相关解决方案