SQL delete command?

后端 未结 7 2239
日久生厌
日久生厌 2020-12-18 02:34

I am having trouble with a simple DELETE statement in SQL with unexpected results , it seems to add the word to the list??. Must be something silly!. but i cannot see it , t

7条回答
  •  借酒劲吻你
    2020-12-18 03:24

    See the code below:

    private void button4_Click(object sender, EventArgs e)
            {
                String st = "DELETE FROM supplier WHERE supplier_id =" + textBox1.Text;
    
            SqlCommand sqlcom = new SqlCommand(st, myConnection);
            try
            {
                sqlcom.ExecuteNonQuery();
                MessageBox.Show("delete successful");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    
    
        private void button6_Click(object sender, EventArgs e)
        {
            String st = "SELECT * FROM supplier";
    
            SqlCommand sqlcom = new SqlCommand(st, myConnection);
            try
            {
                sqlcom.ExecuteNonQuery();
                SqlDataReader reader = sqlcom.ExecuteReader();
                DataTable datatable = new DataTable();
                datatable.Load(reader);
                dataGridView1.DataSource = datatable;
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    

提交回复
热议问题