For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > Using ODBC database









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using ODBC database
Jonathan Blitz

2006-05-31, 7:15 pm

I am using a PostgreSQL database and want to connect to it using ODBC.

I am trying to follow the details but am getting very . Maybe
someone could help me.

I have used an external ODBC connector (libodbc++) to connect. This works
perfectly for fetching data.

Now I want to create fields on a screen taht show data from the database and
don't think I can do it like that.

So - I created a database source using the wizard and use it as a basis to
get data. This works ok but I cannot see how to switch between different
datasources. I tried editing the connection string but it still goes to the
original data source.

I also looked at the online doctumentation and it talks about the CDatabase
class and that seems to be different again!

So, what am I supposed to be using?

Jonathan Blitz
Anykey Limited
Israel


William DePalo [MVP VC++]

2006-05-31, 7:15 pm

"Jonathan Blitz" <jb@anykey.co.il> wrote in message
news:uEaQ4hNhGHA.764@TK2MSFTNGP03.phx.gbl...
>I am using a PostgreSQL database and want to connect to it using ODBC.


OK.

> I have used an external ODBC connector (libodbc++) to connect. This works
> perfectly for fetching data.


I'm not familiar with that class library. Just btw I don't recall having
seen it discussed here.

> So - I created a database source using the wizard and use it as a basis to
> get data. This works ok but I cannot see how to switch between different
> datasources. I tried editing the connection string but it still goes to
> the
> original data source.
>
> I also looked at the online doctumentation and it talks about the
> CDatabase
> class and that seems to be different again!
>
> So, what am I supposed to be using?


Well, you can use a class library or you can use the native ODBC API. In
either case you probably should search for a more appropriate group to post
the question.

That said, I can't help with libodbc or MFC's ODBC classes but at the level
of the API this is the deal:

You allocate a "environment" handle with
SQLAllocHandle(SQL_HANDLE_ENV, ...);

That makes your application a consumer of ODBC services. Within that
environment you can create one or more database "connections". You do that
by calling

SQLAllocHandle(SQL_HANDLE_DBC, ...)

to get an "empty" (my word) handle to a database connection. That done you
can use any of a number of services to connect to a DBMS. Among them is
SQLDriverConnect() which can optionally display dialogs if you have an
"incomplete" (my word) connection string.

Now once you have a connection, you can pass the connection handle to

SQLAllocHandle(SQL_HANDLE_STMT, ...)

to retrieve a statement handle. If you have multiple datasources you just
allocate multiple connection handles, on each connect to a data source and
create a statement handle. The SQL statements that you "prepare" or
"execute" on those statement handles are routed by ODBC to the proper data
source.

--
Regards,
Will

"I'm not ready to make nice, I'm not ready to back down ..."




Jonathan Blitz

2006-05-31, 7:15 pm


>
works[color=darkred]
>
> I'm not familiar with that class library. Just btw I don't recall having
> seen it discussed here.
>


libodbc++ is just an set of classes that are used to wrap the calls to ODBC.
They are really meant for C++ that does not include its own ODBC direct
support.
So, in fact, it does what VC++ does with the code you listed below.

My main problem is how to bind a control on a form to a table in ODBC.
I could easily just get the data and fill the control in a loop but I would
rather not do it if I could avoid it.

.. In either case you probably should search for a more appropriate group to
post
> the question.



I tried to find an appropriate one in the microsoft list but got nowhere.

Jonathan Blitz


William DePalo [MVP VC++]

2006-05-31, 7:15 pm

"Jonathan Blitz" <jb@anykey.co.il> wrote in message
news:uslRBjPhGHA.1272@TK2MSFTNGP03.phx.gbl...
> My main problem is how to bind a control on a form to a table in ODBC.
> I could easily just get the data and fill the control in a loop but I
> would
> rather not do it if I could avoid it.


Sorry, but neither MFC nor WinForms is my forte.

> I tried to find an appropriate one in the microsoft list but got nowhere.


One of these?

microsoft.public.data.odbc
microsoft.public.data.oledb
microsoft.public.vc.mfc

--
Regards,
Will

"I'm not ready to make nice, I'm not ready to back down ..."



Jonathan Blitz

2006-05-31, 7:15 pm

> One of these?
>
> microsoft.public.data.odbc
> microsoft.public.data.oledb
> microsoft.public.vc.mfc


Mmmm.
I just looked in the VC and VStudio lists. :-(

Thx,

Jonathan


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com