Mysql Creating table with c++

Hi everyone i wanted to create a table in my mysql database through c++ windows forms in visual studio.

i use the following code to do it:

MySqlCommand^createtable=gcnew MySqlCommand("Create Table 'database'.'"+this->reg_username_txt->Text+"'('Sender' Varchar(45) NULL, 'Message' VARCHAR(45) NULL);"condatabase);

where reg_username_txt is the name of the textbox that takes username input from user.

but when i run it i get the following error:

You have an error in your SQL syntax;check the manual that corresponds to your Mysql server version for the right syntax to use near ''database.'g'('Sender' VARCHAR(45) NULL, 'Message' Varchar(45) NULL)' at line 1.



Actually i want to make application like chatting in which a table is created of registered username that stores of sender's name as well as messages

thank you.
Mitesh
I use direct ODBC to work with SQL Server, and in that case my sequence of operations is to first create the database, then create the table. If I recall correctly, after I create the database on SQL Server I close all connections, then reopen that specific database connection to create the table. Don't know if MySql operates that way but wouldn't surprise me if it did. Other thing to watch out for is the concept of 'Escape Sequences' for enclosing text. They can be just about anything. I believe MS Access uses double quotes. I think SQL Server uses single quotes. Hope this helps.
I would store the sql cmd first in a string and use a MessageBox to see if the string is correct.

I would store the sql cmd first in a string and use a MessageBox to see if the string is correct.


Very good idea from Thomas. Its really hard to read things like that (dynamically composed strings). Output them to a debug output file or MessageBox before using them. Usually the problems jump right out at you then.
ok i got the problem...it should be back-tick (`) instead of single-quotes (').Thanks a lot sir.
Sir i just want to confirm that is my idea correct that using server database and mysql tables to store messages and convey those to users who login into the application?
Sorry, I wouldn't know.
Topic archived. No new replies allowed.