error in sentence mysql
#1

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
.
#2

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

#3

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"  Sad  Sad  Sad
#4

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+";

#5

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

#6
Thanks Wizatek and ZaTii, problem solved  Big Grin  Big Grin  Big Grin  Big Grin  Big Grin  Big Grin  Big Grin



Forum Jump:


Users browsing this thread: 1 Guest(s)