![]() |
|
error in sentence mysql - Printable Version +- LCKB (https://lckb.dev/forum) +-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109) +--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196) +---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192) +---- Thread: error in sentence mysql (/showthread.php?tid=3131) |
- ucaff - 05-14-2015 Hello guys I take the data from a Datragrid.... " IniRead(); string constring = "datasource=" + Host.Text + ";port=3306;username=" + User.Text + ";password=" + Passwd.Text; MySqlConnection conDataBase = new MySqlConnection(constring); string Query = "DELETE " + DataBase.Text + "FROM .t_quest WHERE a_index='" + QuestID.Text + "'"; MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); MySqlDataReader myReader; try { conDataBase.Open(); myReader = cmdDataBase.ExecuteReader(); MessageBox.Show("(DELETE OK)!"); while (myReader.Read()) { } } catch (Exception ex) { MessageBox.Show(ex.Message); } SelectDB(); " ........Someone could correct code ?, failed to make it work. I want to delete rows in the db.... from already thank you very much for your help . - Wizatek - 05-14-2015 if you want to delete a entire row the query would be like this DELETE FROM t_quest WHERE a_index = 1 That would delete quest 1 - ucaff - 05-14-2015 In your example "should look like? private void Button3_Click(object sender, EventArgs e) { IniRead(); string constring = "datasource=" + Host.Text + ";port=3306;username=" + User.Text + ";password=" + Passwd.Text; MySqlConnection conDataBase = new MySqlConnection(constring); string Query = "DELETE FROM t_quest WHERE a_index ='"+QuestID.Text+"'"; MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase); MySqlDataReader myReader; try { conDataBase.Open(); myReader = cmdDataBase.ExecuteReader(); MessageBox.Show("(DELETE OK)!"); while (myReader.Read()) { } } catch (Exception ex) { MessageBox.Show(ex.Message); } SelectDB(); }..... Not work Only a sign that says "no Database Select" ![]() - Wizatek - 05-14-2015 add the database in your connection string, dbname= or add it in the query, DELETE FROM newproject_data.t_quest WHERE a_index = "+QuestID.Text+"; - ZaTii - 05-14-2015 string Query = "DELETE FROM " + DataBase.Text + ".t_quest WHERE a_index = " + QuestID.Text + ";"; that should mostly work And for the variables i would load them in a public static string when the first form i loaded. Then u can acces them by Form1."variable" so u dont need 4 textboxes in every Form who are invisible to load the db settings - ucaff - 05-14-2015 Thanks Wizatek and ZaTii, problem solved ![]() |