Search code examples
c++sqlvisual-c++oledb

How do I create a create and execute an SQL command using OleDB directly?


I want to use the OleDB interfaces directly to open a connection to a DB, create a command and executing it (for example using the ICommandText interface).

The main thing I can't find is how to create the connection and the command object and how to connect the object that implements the ICommandText to the connection. In ADO I would just use the ActiveConnection property but I want to do this directly on the OleDB interfaces.

Also, if anyone can recommend a tutorial to OleDB, ether online or a book, free or not that would be great (but a tutorial and not just a reference / API)

I'm using C++ but any native code would be fine.


Solution

  • MSDN has a lot on this. http://msdn.microsoft.com/en-us/library/502e07a7.aspx is a sort of index into it, including several pages of concepts and others of samples. Should get you started.

    http://msdn.microsoft.com/en-us/library/8kaf36d4.aspx specifically starts a File, New, Project and gets you connected to the db and selecting some data.