title: How to input a value on a web form and store it as numeric in SQL Server
body: <p>I have the following code:</p>
  
  <pre><code>protected void btn_add_Click(object sender, EventArgs e)
  {
      if (intSlipID_srch.Text == "")
          lblStatus.Text = "Please enter a Slip ID.  ";
      string connection =
      WebConfigurationManager.ConnectionStrings["popeye_marina"].ConnectionString;
      SqlConnection con = new SqlConnection(connection);
  
      // Clear text controls
  
      txtSlipLength.Text = string.Empty;
      txtSlipWidth.Text = string.Empty;
      txtCovered.Text = string.Empty;
      txtFee.Text = string.Empty;
      intDockID.Text = string.Empty;
      intBoatID.Text = string.Empty;
  
      // Create Update SQL string
  
      string insertSQL;
      insertSQL = "INSERT INTO slip (";
      insertSQL += "slip_length, slip_width, ";
      insertSQL += "covered, annual_fee, dock_id, boat_id) ";
      insertSQL += "VALUES (";
      insertSQL += "@slip_length, @slip_width, @covered, ";
      insertSQL += "@fee, @dockID, @boatID)";
  
      SqlCommand cmd = new SqlCommand(insertSQL, con);
      cmd.Parameters.AddWithValue("@slip_length", txtSlipLength.Text);
  
      cmd.Parameters.AddWithValue("@slip_width", txtSlipWidth.Text);
      cmd.Parameters.AddWithValue("@covered", txtCovered.Text);
      cmd.Parameters.AddWithValue("@fee", txtFee.Text);
      cmd.Parameters.AddWithValue("@dockID", intDockID.Text);
      cmd.Parameters.AddWithValue("@boatID", intBoatID.Text);
      int inserted = 0;
      try
      {
          con.Open();
          inserted = cmd.ExecuteNonQuery();
          lblStatus.Text = inserted.ToString() + " record inserted.";
      }
      catch (Exception err)
      {
          lblStatus.Text = "Error saving Slip.  ";
          lblStatus.Text += err.Message;
      }
      finally
      {
          con.Close();
      }
  }
  </code></pre>
  
  <p>The target database column is numeric. When I run the web form and enter a numeric value, I get the error:</p>
  
  <blockquote>
    <p>Error converting data type nvarchar to numeric</p>
  </blockquote>
  
  <p>Can you tell me how to correct this error?</p>