Re: why cant I get data from the ACCESS
From: Tim (Tim_at_NoSpam)
Date: 02/19/04
- Next message: Jase: "Re: Displaying Multiple Text Lines At Runtime"
- Previous message: Jagadeesh VN: "Re: MSComm obj."
- In reply to: Steven_chaoxiang: "why cant I get data from the ACCESS"
- Next in thread: Jase: "Re: why cant I get data from the ACCESS"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Feb 2004 18:56:34 +1300
Steven,
>From what you are saying I think you need the path to the database in the
connection string along these lines - note this is an ODBC connection
string, not an ADO one, so amend it to use the details you were using:
CString strDSN;
strDSN.Format(_T("PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=%s;"),
strDBPath);
IE from your code:
CString strDSN;
strDSN.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s;"),
strDBPath);
_connectionPtr->Open(strDSN,"","",adModeUnknown)
where strDBPath is the full path to the file EG "c:\My Databases\xx.mdb".
It would be prudent also to wrap your database calls in try / catch handlers
with e->ReportError(); so that you can see what the error messages are.
In ODBC with CDatabase it would be like this:
try
{
m_db.OpenEx(strDSN);
}
catch(CDBException* e)
{
e->ReportError();
e->Delete();
}
The exception types for ADO are not CDBException.
- Tim
"Steven_chaoxiang" <anonymous@discussions.microsoft.com> wrote in message
news:6DA9F1FA-E6E1-4940-A333-E6CCE7E82704@microsoft.com...
> Hello,everyone:
> I have got a question in MFC, the function of my application is that I
will get data from the ACCESS.My client's damand is that before i get the
data, a dialogbox(CFileDialog used) must be show first in order to save the
file clients input.I use the Cfiledialog.DoModel() to show the dialogbox for
client to save the path of file. However if the path of the file client
input is not at the same catalog as the place where .mdb is ,when you get
the data from the Access using
_connectionPtr->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=xx.mdb",""
,"",adModeUnknown), a excepion will be thrown. I am totally at loss as to
what is wrong with it. To my surprise, if you save the path of the file at
the same catalog as the catalog where xx.mdb is,the applictaion is totally
ok.I wonder who knows the solution to the problem,if someone knows ,please
send the answer to this discussion or send E-mail to me(zlx0615@sina.com.cn)
as quickly as possible,thank you ever so much!!!
- Next message: Jase: "Re: Displaying Multiple Text Lines At Runtime"
- Previous message: Jagadeesh VN: "Re: MSComm obj."
- In reply to: Steven_chaoxiang: "why cant I get data from the ACCESS"
- Next in thread: Jase: "Re: why cant I get data from the ACCESS"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|