MySQL connection with C# through PHPMyAdmin created database -


we sitting problem regarding mysql database insertion. have installed .net connector , added mysql.data.dll, mysql.web.dll, mysql.entity.dll /bin. displayed in code below, using right namespace. however, when try , insert data through website, nothing gets inserted. details database connection provided webhotel. domain location: http://testing.cce-solutions.dk/testbooking/is/interested/

c# code:

protected void button1_click(object sender, eventargs e) {     mysql.data.mysqlclient.mysqlconnection connection;     string server = "db.cce-solutions.dk";     string database = "web626445";     string uid = "******";     string password = "******";     string connectionstring;     connectionstring = "server=" + server + ";" + "database=" +     database + ";" + "uid=" + uid + ";" + "password=" + password + ";";     connection = new mysqlconnection(connectionstring);     try     {         connection.connectionstring = connectionstring;         connection.open();         mysqlcommand cmd = new mysqlcommand("insert  web626445 (yourname,youremail,yourphone,category,description) values(@name,@email,@telephone,@category,@description)", connection);         cmd.parameters.addwithvalue("@name", yourname.text);         cmd.parameters.addwithvalue("@email", youremail.text);         cmd.parameters.addwithvalue("@telephone", yourphone.text);         cmd.parameters.addwithvalue("@category", category.selecteditem.value);         cmd.parameters.addwithvalue("@description", description.text);         cmd.executenonquery();     }     catch (exception ex)     {         displaymessage.text = "error occured. please try again later.";     }     connection.close();     }} 

edit: firstly, answers! have implemented rahul , activehigh's answers , updated code. furthermore, have added way check if connection success or not. when try insert data error message. test location still same. here image of table in database: https://www.dropbox.com/s/g2c70ty9qb1h7bw/screenshotdatabase.png have idea going wrong or idea how debug it?

protected void button1_click(object sender, eventargs e) {     mysql.data.mysqlclient.mysqlconnection connection;     string server = "db.cce-solutions.dk";     string database = "web626445";     string uid = "******";     string password = "******";     string connectionstring;     connectionstring = "server=" + server + ";" + "database=" +     database + ";" + "uid=" + uid + ";" + "password=" + password + ";";       connection = new mysqlconnection(connectionstring);      try     {         connection.open();         if (connection.state == connectionstate.open)         {             displaymessage.text = "data entered succesfully.";             mysqlcommand cmd = new mysqlcommand("insert  booking (yourname,youremail,yourphone,category,date,description) values(@name,@email,@telephone,@category,@date,@description)", connection);             cmd.parameters.addwithvalue("@name", yourname.text);             cmd.parameters.addwithvalue("@email", youremail.text);             cmd.parameters.addwithvalue("@telephone", yourphone.text);             cmd.parameters.addwithvalue("@category", category.selecteditem.value);             cmd.parameters.addwithvalue("@date", "test");             cmd.parameters.addwithvalue("@description", description.text);             cmd.executenonquery();         }         else         {             displaymessage.text = "database connection failed.";         }       }     catch (exception ex)     {         displaymessage.text = "error occured. please try again later.";     }      connection.close(); 

you using database name inside insert statement-

...  string server = "db.cce-solutions.dk";     string database = "web626445";     string uid = "******"; ...  mysqlcommand cmd = new mysqlcommand("insert  web626445 (yourname,youremail,yourphone,category,description) values(@name,@email,@telephone,@category,@description)", connection); 

i see web626445 database not table. use table name instead. since have wrapped try block cannot see error.

and check have table correctly created.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -