Re: Cannot read data from Access 2007 database
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 11 Jan 2007 09:29:20 -0500
Glad to hear it worked out for you. Thanks for the follow-up.
Just wondering if you would have received this answer in a vc group,
saving you some time...
dbouthillier wrote:
I figured out my problem. Turns out i was trying to access the fieldshttp://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en
incorrectly. If I use a variant like this:
_variant_t index;
index.vt = VT_I2;
index.iVal = 1;
and then pass this variant to the GetItem() function call, i can
successfully read the value of a field!!
"dbouthillier" wrote:
Hi. I'm trying to read data from an Access 2007 database. I'm
working with VS 2005 C++ on Windows XP SP2. I downloaded the 2007
Office System Driver found at
and installed it. My MDAC version is 2.81.1117.0.
I'm using ADO (msado15.dll) to acces the Access database. Here is
some very simple sample code of mine that attemps to read the "DATE"
field.
void CAccess2007Doc::OnFileOpen()
{
if (SUCCEEDED(m_oDatabase.CreateInstance(__uuidof(Connection))))
{
if
(SUCCEEDED(m_oDatabase->Open("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\\TestData\\Database1.accdb;Persist Security Info=False",
"", "", -1))) {
m_oDatabase->CursorLocation = adUseClient;
if (SUCCEEDED(m_oRecordSet.CreateInstance(__uuidof(Recordset))))
{
if (SUCCEEDED(m_oRecordSet->Open("Select * FROM Table1",
m_oDatabase.GetInterfacePtr(), adOpenDynamic, adLockOptimistic,
adCmdText))) {
if (SUCCEEDED(m_oRecordSet->MoveFirst()))
{
_variant_t value =
m_oRecordSet->Fields->GetItem("DATE")->Value; }
}
}
}
}
return;
}
Everytime I try to get the value of a field, any field, ADO always
throws an exception. I put a try/catch around the code and the error
description is always "Unknown error 0x800A0CC1"
I'm new to the world of ADO so any help would be greatly appreciated!
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
.
- Prev by Date: Re: Stand Alone Recordsets
- Next by Date: error of reading with ADO
- Previous by thread: Re: Cannot read data from Access 2007 database
- Next by thread: Retrieve Cyrillic data
- Index(es):
Relevant Pages
|
Loading