如何在 C# 中使用 ComboBox 删除数据库中的数据?

How can I Delete Data in a Database Using ComboBox in C#?

Here is a Picture of My Table Named CategoryTable

我使用以下代码从上面删除数据 Table 使用 ComboBox 命名为 SelectCategoryComboBox 但它确实 nothing.it 就像一个 un-编程按钮。 这是我的代码:

try
{
  String conString =   ConfigurationManager.ConnectionStrings["mfcdb"].ConnectionString;
                     String query = "DELETE FROM CategoryTable WHERE     CategoryName='" + SelectCategoryComboBox.SelectedText + "'";

    using (SqlConnection con = new SqlConnection(conString))
    {
        SqlCommand cmd = new SqlCommand(query, con);
        con.Open();
        cmd.ExecuteNonQuery();
    }
  }
  catch{
  MessageBox.Show("Error");
}

改变

SelectCategoryComboBox.SelectedText

SelectCategoryComboBox.SelectedItem.ToString()