Re: C++ support for ADO
- From: Neil B <NeilB@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 3 Mar 2007 08:44:03 -0800
We are making progress thanks to your help.
We can connect to the database, open the record set and read field values.
We ran into a problem trying to typecast a void* to a ADODB::_RecordsetPtr.
The code is as follows:
//*************************************************
void CDataBase::SetActiveRecordSet(CString recordSet)
//*************************************************
{
void* recordSetPtr;
// Don't change it - if no record set specified
if (recordSet.IsEmpty()) return;
// Change the active record set - if it's in the map
if (!m_recordSetMap.Lookup(recordSet, recordSetPtr)) return;
m_activeRecordSet=(ADODB::_RecordsetPtr) recordSetPtr;
}
The last line will not compile. How do you typecast to a ADODB::_RecordsetPtr?
There didn't seem to be a problem typecasting it to a void*.
Thanks, Neil
"Bob Barrows [MVP]" wrote:
I've never seen a reference for these objects. However, as I understand.
it, they are the same objects that are documented in the link I gave you
earlier. Try this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdhowhowvcusersshouldreadadodocumentation.asp
Neil B wrote:
Does anyone know where I can find the class information for
ADODB::_ConnectionPtr and ADODB::_RecordsetPtr?
What about any other ADODB:: classes, enum's etc. ?
Thanks, Neil
"seabee" wrote:
Source=Finances 2006 ? As finance bods do absolutely everything
with Excel are you trying to open a work-book? Because if you are,
you need the Extended Properties parameter. The following works in
VS6.
CString sTx, sFilePath="c:\Accounts2006.xls";
_bstr_t a,b;
_ConnectionPtr pConn = NULL;
TESTHR(pConn.CreateInstance( __uuidof( Connection )));
sTx.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s;
Extended Properties=\"Excel 8.0;\"",sFilePath);
pConn->Open(sTx.AllocSysString(),a,b,0L);
seabee
Thanks for the overview, it was enlightening.
In answer to your question I'm interested in ADO not the ADO.net.
I have the following code compiled and running up to the OPEN
Connection:
//*************************************************
bool CDataBase::Open(CString userName, CString password, CString
cnnStr) //*************************************************
{
HRESULT hr;
_bstr_t errorMsg;
_bstr_t _userName, _password, _cnnStr;
_userName=LPCTSTR(userName);
_password=LPCTSTR(password);
_cnnStr=LPCTSTR(cnnStr);
// Create a connection object
ADODB::_ConnectionPtr connection;
hr = connection.CreateInstance(__uuidof(ADODB::Connection));
// Create a record set object
ADODB::_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(ADODB::Recordset));
// Open a connection to a data base
connection->CursorLocation = ADODB::adUseClient;
try {hr=connection->Open(L"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Finances 2006;", L"admin", L"049846234640",
ADODB::adConnectUnspecified); }
catch(_com_error &e)
{
// Handle errors
errorMsg=e.Description();
return 0;
}
At this point I get the errorMsg of :
"Cannot start your application. The workgroup information file is
missing or
opened exclusively by another user."
Not familiar with workgroup information file.
Is this related to the Initial Catalog command?
If so how do you set it up? Or where do you find it?
Where can I get the class info on ADODB::_ConnectionPtr and
ADODB::_RecordsetPtr ?
And how can I convert _bstr_t to a CString?
These are a few of the areas I'm have difficulty finding.
Any help you can give would be greatly appreciated.
Thanks, Nei
"Ralph" wrote:
"Neil B" <NeilB@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:52804A7A-CC60-4F1D-9FBE-E472B642C0E4@xxxxxxxxxxxxxxxx
I'm in the process of updating an app from ODBC to ADO in VS
using C++ (MFC).
I'm use to having the interface classes defined.
In my attempts to work with ADO I can't find information on
classes and methods that I'm executing.
I'm told that ADO is the strategic direction of MS.
What am I missing here???
It's no fun programming in the blind!!!
Can anyone provide some direction?
Thanks, Neil
The issue you are having is not that little information is
available, it is
simply that it is located under something that probably isn't
immediately recognizeable as useful. Also because of the amazing
versatility of C++ there are more that one way to work with "ADO".
[First, are you using .Net (C++/cli, ADO.Net)? If so, this this
newsgroup isn't for you. It sounds like you are using classic MFC
and plain-ol-ADO, but I just wanted to make sure. <g>]
ADO is an ActiveX Data Access Library (COM) that serves as a
wrapper for OLE
DB. Stickly speaking, this is the true "ADO". It was designed for
'higher-level languages' such as VB, VBA, etc.
You can use ADO components directly from C++, a la VB, by using the
#import
statement and accessing the library just as you would any other COM
component.
For this practically any ADO samples, books, and articles are
useful. And there are a ton of them.
When using MFC and DAO/ODBC you used the CDao... data classes.
There are also COle... data classes for working with ADO/OLE DB.
(They sort of wrap the ADO wrappers. Confused yet? <g>) So you can
use "ADO" in this way as well, though are a bit limited compared
to the full featured ADO library. (Poor Error handling is biggest
fault.)
Look for information on COle.... classes.
You can also use the OLE SDK. Which allows you to more directly
access ADO
and OLE DB interfaces/objects. It resolves the Error handling
problems, but
is sort of an odd mix between two worlds. There is probably the
least amount
of information using this method.
Check out "OLE DB, adoid.h, and adoint.h".
Last but likely best is accessing OLE DB directly and skip using
ADO - this
method will give the best performance and the most control. ie,
write your
own "ADO".
Look for "VC++ OLE DB programming"
hth
-ralph
--
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.
- Follow-Ups:
- Re: C++ support for ADO
- From: Bob Barrows [MVP]
- Re: C++ support for ADO
- References:
- Re: C++ support for ADO
- From: seabee
- Re: C++ support for ADO
- From: Neil B
- Re: C++ support for ADO
- From: Bob Barrows [MVP]
- Re: C++ support for ADO
- Prev by Date: Re: Access - three IIF expression
- Next by Date: Re: C++ support for ADO
- Previous by thread: Re: C++ support for ADO
- Next by thread: Re: C++ support for ADO
- Index(es):
Relevant Pages
|