SQL delete command?

后端 未结 7 1218
死守一世寂寞
死守一世寂寞 2020-12-18 02:59

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:28

    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);
            }
        }
    
    0 讨论(0)
提交回复
热议问题