Hello People.

I would like to ask you're assistance with a little problem I am having. When I execute this code:

string sql2 = "INSERT INTO worlds (worlds_ID,worlds_active,worlds_name,worlds_x,worlds_y) VALUES ('', '1', 'Test', '250', '250');";
MySqlCommand cmd = new MySqlCommand(sql2, OpenCon());
addtolog("server", "World Created");

it does not make the new row in the databse, but it does execute the addtolog command.
Also the OpenCom() is not the problem, because it works fine with a SELECT query. I suspect that the problem lies with the query.

Could someone please tell me what is wrong with the code?

Thanks in advance :)
Dirk

Recommended Answers

All 2 Replies

You aren't executing the command at all. You're defining it and adding the SQL statement and the connection but you also need to add

cmd.ExecuteNonQuery();

to make the command actually affect the database. I'm assuming you have the opened the connection as well.

Thank you very much for your reply. How can I be such a stupic person not to realise I didn't actually execute it xD

Well, back to coding :)

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.