Re: Cannot read data from Access 2007 database



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 fields
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

http://www.microsoft.com/downloads/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en
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.


.



Relevant Pages

  • Re: How to Mimic Access Externally Linked Tables using ADO?
    ... > using SQL Server for efficiency reasons. ... > connection up programmatically using ADO or ADOX or some SQL Server API? ... >> newsgroup, but if you have a good reason to send me e-mail, you'll find ... ADO does not have a query engine. ...
    (microsoft.public.data.ado)
  • Re: Brand Spankin Newbie ADO.NET Question
    ... This posting is provided "AS IS" with no warranties, and confers no rights. ... > examples in my Apress book "ADO.NET and ADO Examples and Best Practices" ... > Microsoft MVP ... > Please reply only to the newsgroup so that others can benefit. ...
    (microsoft.public.vb.database.ado)
  • Re: Form data output
    ... > CSV file. ... Access to extract the data from Word or the text file (ADO or DAO ... reply in the newsgroup and not by e-mail :-) ...
    (microsoft.public.word.vba.userforms)
  • Re: ADO and "Bad" Dates
    ... > 6 bytes in the ADO field object. ... >> William (Bill) Vaughn ... >> Microsoft MVP ... >> Please reply only to the newsgroup so that others can benefit. ...
    (microsoft.public.vb.database.ado)
  • Re: ADO and "Bad" Dates
    ... > 6 bytes in the ADO field object. ... >> William (Bill) Vaughn ... >> Microsoft MVP ... >> Please reply only to the newsgroup so that others can benefit. ...
    (microsoft.public.data.ado)

Loading