#include <iostream> 
#include <string>

using namespace std;


class w {

public:
    void InsertRow(String* myConnection)
    {
        // If the connection string is null, use a default.
        if (myConnection->Equals(S""))
        {
            myConnection = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=idb;";
        }
        OdbcConnection* myConn = new OdbcConnection(myConnection);
        String* myInsertQuery = S"INSERT INTO test (id)";
        OdbcCommand* myOdbcCommand = new OdbcCommand(myInsertQuery);
        myOdbcCommand->Connection = myConn;
        myConn->Open();
        myOdbcCommand->ExecuteNonQuery();
        myOdbcCommand->Connection->Close();
    }
};

hai i m trying to connect visual studio C++ to mysql, i m using odbc method... i have connect the database to the visual studio, but i dnt know the code need to connect in the c++ ( example for vb.net we will use the dim.... database name all and establish connection) i need the same thing in c++,

i have try this code ealier post above but its not working>..

You need to start learning ODBC in C from a tutorial. Lots of them on the net, including this one. Its a lot more difficult than what you knew in VB, so be patient and study the tutorial.

There are a few c++ wrapper classes to make it a little easier for you. Just google for them and you will find them. Some are free but some are not.

And for the record VC++ is not a language. Its just an IDE and compiler which lets you write standard c++ and c code. You shouldn't confuse the two.

Hi

we had similar question recently. You may look here. Possibly you already know this older post by yourself.

If you don't like classless plain odbc (mysql: Connector/ODBC) you could make use of mysql: Connector/C++. There are also nice tutorials on Connector/C++.

-- tesu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.