Connecting to MySQL with a WindowsForm application
Posted by: Tanya Le Sage
Date: March 30, 2012 01:31AM

Hi,

I have created a windows console application using VS2010 C++ which connects to a MySQL database using the SQLAPI++ connector and the code below:

int main(int argc, char* argv[])
{
SAConnection con; //create connection object
try
{
con.Connect("test","root","....",SA_MySQL_Client);
printf("We are connected!\n");
con.Disconnect();
printf("We are disconnected!\n");
}

catch(SAException &x)
{
try
{
con.Rollback();
}
catch(SAException &)
{

}

printf("%s\n", (const char*)x.ErrText());
}

cin.get();
return 0;
}

I have tested this and it connects and disconnects ok. I now want to include this in a windows form application that I have. Can anybody tell me how to do this? I'm new to MySQL and C++ so need step by step instructions. When I include it in my form.h (without the printf functions, cin.get(), and return 0) I get the following errors:

error C2059: syntax error : 'try'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
error C2059: syntax error : 'catch'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)

I have included the same folders and libraries as before.

Thank you so much for any help you can give me!



Edited 1 time(s). Last edit at 03/30/2012 02:05AM by Tanya Le Sage.

Options: ReplyQuote


Subject
Views
Written By
Posted
Connecting to MySQL with a WindowsForm application
1379
March 30, 2012 01:31AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.