Ok jetzt ganz langsam,
ich habe eine *.h und *.cpp
in *.h steht :
class CTabell
{
public:
CTabell()
{
memset( (void*)this, 0, sizeof(*this) );
};
// Die variablen von CTabell
BEGIN_COLUMN_MAP(CTabell)
//Die Spalten von CTabell
END_COLUMN_MAP()
};
class testSet : public CCommand<CAccessor<CTabell> >
{
public:
// Setzen der Parameter für den Zugriff auf die richtige DB.
void SetDBParams(const CString& server, const CString& catalog, const CString& user, const CString& passwd);
// DataSource und Session öffnen
HRESULT OpenDataSource();
private:
CString mServer;
CString mCatalog;
CString mUser;
CString mPasswd;
};
[/PHP]
in *.cpp steht die SetDBParams und OpenDataSource :
[PHP]
HRESULT OpenDB::OpenDataSource()
{
CDataSource db;
HRESULT hr = S_OK;
CDBPropSet dbinit(DBPROPSET_DBINIT);
// Windows Authenzifirung oder SQL Server
if(!mUser.IsEmpty())
{
dbinit.AddProperty(DBPROP_AUTH_USERID, mUser);
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, mPasswd);
}
else
{
// Windows-User
dbinit.AddProperty(DBPROP_AUTH_INTEGRATED, OLESTR("SSPI"));
}
dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
dbinit.AddProperty(DBPROP_INIT_CATALOG, mCatalog);
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, mServer);
dbinit.AddProperty(DBPROP_INIT_LCID, (long)1031);
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
hr = db.OpenWithServiceComponents(_T("SQLOLEDB.1"), &dbinit);
if (FAILED(hr))
return hr;
CSession session;
session.Open(db);
if (FAILED(hr))
return hr;
CDBPropSet propset(DBPROPSET_ROWSET);
propset.AddProperty(DBPROP_MULTIPLECONNECTIONS, true);
propset.AddProperty(DBPROP_IRowsetScroll, true);
propset.AddProperty(DBPROP_IRowsetChange, true);
propset.AddProperty(DBPROP_UPDATABILITY, (long)0 );
if(FAILED(hr = CCommand<CAccessor<CTabell> >::Open(session, "SELECT * FROM dbo.Tabell ", &propset)))
{
AtlTraceErrorRecords(hr);
return hr;
}
return MoveNext();
}
so rufe ich es:
OpenDB opendb;
opendb.SetDBParams(....);
opendb.OpenDataSource();
while(S_OK == opendb.cmd.MoveNext())
{
int k = opendb.m_ver;
}
[/PHP]
gibt es eine andere Möglichkeit, ist es überhaupt korrekt was ich mache ????