OLE DB and IRowsetChange::SetData
-
Hello, I'm trying to write an OLE DB Wrapper class and have created a function called SetStringFieldValue and inside that function I need to set 1 columns data to the string passed to the function. I have yet to find any examples of SetData anywhere and for some reason its not working for me. Any help is greatly appreciated. void COleDBWrapper::SetStringFieldValue(int nIndex, LPCTSTR lpszValue) { CString strValue(lpszValue); IRowsetChange* pIRowsetChange = (IRowsetChange*)m_pUnkRowsetChange; IRowsetUpdate* pIRowsetUpdate = (IRowsetUpdate*)m_pUnkRowsetUpdate; IAccessor* pIAccessor = NULL; HACCESSOR hAccessor; ULONG cBindings = 1; DBBINDING rgBinding[1]; memset(rgBinding, 0, sizeof(DBBINDING)); char szValue[50]; _tcscpy(szValue, strValue.GetBuffer(0)); rgBinding[0].iOrdinal = nIndex; rgBinding[0].dwPart = DBPART_VALUE|DBPART_STATUS|DBPART_LENGTH; rgBinding[0].obLength = (strValue.GetLength() + 1) * sizeof(TCHAR); rgBinding[0].obStatus = (strValue.GetLength() + 1) * sizeof(TCHAR); (CString)rgBinding[0].obValue = szValue; // -- DOESN'T DO JACK! -- // rgBinding[0].wType = DBTYPE_STR; rgBinding[0].pTypeInfo = NULL; rgBinding[0].pObject = NULL; rgBinding[0].pBindExt = NULL; rgBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED; rgBinding[0].cbMaxLen = (strValue.GetLength() + 1) * sizeof(TCHAR); rgBinding[0].dwFlags = 0; HRESULT hr = m_pUnkRowset->QueryInterface(IID_IAccessor, (void**)&pIAccessor); if (FAILED(hr)) return; hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1, rgBinding, 0, &hAccessor, NULL); if (FAILED(hr)) return; hr = pIRowsetChange->SetData(m_hRow, hAccessor, szValue); // hr is ALWAYS DB_E_ERRORSOCCURRED } Bret Faller Odyssey Computing, Inc.
-
Hello, I'm trying to write an OLE DB Wrapper class and have created a function called SetStringFieldValue and inside that function I need to set 1 columns data to the string passed to the function. I have yet to find any examples of SetData anywhere and for some reason its not working for me. Any help is greatly appreciated. void COleDBWrapper::SetStringFieldValue(int nIndex, LPCTSTR lpszValue) { CString strValue(lpszValue); IRowsetChange* pIRowsetChange = (IRowsetChange*)m_pUnkRowsetChange; IRowsetUpdate* pIRowsetUpdate = (IRowsetUpdate*)m_pUnkRowsetUpdate; IAccessor* pIAccessor = NULL; HACCESSOR hAccessor; ULONG cBindings = 1; DBBINDING rgBinding[1]; memset(rgBinding, 0, sizeof(DBBINDING)); char szValue[50]; _tcscpy(szValue, strValue.GetBuffer(0)); rgBinding[0].iOrdinal = nIndex; rgBinding[0].dwPart = DBPART_VALUE|DBPART_STATUS|DBPART_LENGTH; rgBinding[0].obLength = (strValue.GetLength() + 1) * sizeof(TCHAR); rgBinding[0].obStatus = (strValue.GetLength() + 1) * sizeof(TCHAR); (CString)rgBinding[0].obValue = szValue; // -- DOESN'T DO JACK! -- // rgBinding[0].wType = DBTYPE_STR; rgBinding[0].pTypeInfo = NULL; rgBinding[0].pObject = NULL; rgBinding[0].pBindExt = NULL; rgBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED; rgBinding[0].cbMaxLen = (strValue.GetLength() + 1) * sizeof(TCHAR); rgBinding[0].dwFlags = 0; HRESULT hr = m_pUnkRowset->QueryInterface(IID_IAccessor, (void**)&pIAccessor); if (FAILED(hr)) return; hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 1, rgBinding, 0, &hAccessor, NULL); if (FAILED(hr)) return; hr = pIRowsetChange->SetData(m_hRow, hAccessor, szValue); // hr is ALWAYS DB_E_ERRORSOCCURRED } Bret Faller Odyssey Computing, Inc.
I'm trying to write an OLE DB Wrapper class It sounds like reinventing the wheel - can't you use ATL OLEDB consumer templates? hr is ALWAYS DB_E_ERRORSOCCURRED IErrorRecords should give you more detailed information. See DBViewer sample for details. You may also check the status variables associated with fields. Tomasz Sowinski -- http://www.shooltz.com
-
I'm trying to write an OLE DB Wrapper class It sounds like reinventing the wheel - can't you use ATL OLEDB consumer templates? hr is ALWAYS DB_E_ERRORSOCCURRED IErrorRecords should give you more detailed information. See DBViewer sample for details. You may also check the status variables associated with fields. Tomasz Sowinski -- http://www.shooltz.com
IErrorRecords::GetDescription and GetSource both give me "M" so they were no help. Also, I am writing my own wrapper class because the templates are ok but they are still too primative. Thank you for your response. Bret Faller Odyssey Computing, Inc.