+ 1
i did connect c# with mysql xampp but my app does not write and read from databas >>>??
String connectionstring = "datasource = localhost;username = wail;password =; database = wail"; string query = "INSERT INTO `name`(`jobs`) VALUES(1258)"; MySqlConnection DBconnection = new MySqlConnection(connectionstring); DBconnection.Open(); MySqlCommand mySqlCommend = new MySqlCommand(query, DBconnection); DBconnection.Close();
2 Answers
+ 2
you have connected to the database and disconnected well but forgot to execute the query. call mySqlCommend.ExecuteNonQuery() before closing the connection. don't forget to enclose this snippets in a try block and let the catch block receives the errors if any. come back of you got any errors
+ 1
This is because on line 4 of your code, you are creating a command object and instantiating it with your query and db connection, but you are not doing anything with it after that. This line is just defining your command. You need to call one of the execute methods to actually run your query on the database. See this link for the definition of the methods available to you. https://dev.mysql.com/doc/dev/connector-net/6.10/html/T_MySql_Data_MySqlClient_MySqlCommand.htm