Mysql Creating table with c++ forms

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
Do not put the table name in single quotation marks.

Instead of creating a new table for each user you should consider to make the username a field of the table. That would make the processing easier.
Sorry sir i tried that but i get the same error (without quotation marks for tablename)
Sir if i make username a field of table then how should i arrange sender's name and their messages in the table.CAn you please help me out?
Thank you
Sorry for the late reply...

i get the same error (without quotation marks for tablename)
There are no single quotation marks within the whole statement. In order to learn more about sql statements I suggest that you take a look here:

https://www.w3schools.com/sql/

Sir if i make username a field of table then how should i arrange sender's name and their messages in the table
My idea would be create two tables:

User
(
Id INT
Name TEXT
)

Message
(
Id INT
FromUserId INT
ToUserId INT
Content TEXT
)

So you are refering to the user via their ids.

Further more I suggest to create a test database with the MySQL console/workbench. Thus test the statements before you actually use them in your code.
Thanks alot sir...i got the issue it should be back-tick(`) instead of single quotes(')...
Topic archived. No new replies allowed.