title: Delete a row from a table, specified by the user, with the click of a button in C#
body: <p>I am using Visual Studio 2019 Winforms C# .NET Framework and in the Winforms project, there is a textbox and a button.</p>
  <p>When I type a parameter name in the textbox and click the button, I want to delete the row from the table called &quot;Serial_Key&quot;.</p>
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      string mainconn = ConfigurationManager.ConnectionStrings[&quot;Myconnection&quot;].ConnectionString;
      SqlConnection sqlconn2 = new SqlConnection(mainconn);
      string sqlquery = &quot;select * from [dbo].[Serial-Keys] where Serial_Key=@Serial_Key&quot;;
      sqlconn2.Open();
      SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn2);
      sqlcomm.Parameters.AddWithValue(&quot;@Serial_Key&quot;, SerialKeyBox.Text);
      SqlDataAdapter sda = new SqlDataAdapter(sqlcomm);
      DataTable dt = new DataTable();
      sda.Fill(dt);
      sqlcomm.ExecuteNonQuery();
      if (dt.Rows.Count &gt; 0)
      {
          Cursor.Current = Cursors.WaitCursor;
          try
          {
              
          }
          catch (Exception)
          {
  
          }
          Cursor.Current = Cursors.Default;
      }
      else
      {
          MessageBox.Show(&quot;Invalid Serial Key!&quot;);
          label7.Text = &quot;Serial Key Rejected...&quot;;
      }
  }
  </code></pre>