title: Call a stored procedure with parameter in c#
body: <p>I'm able to delete, insert and update in my program and I try to do an insert by calling a created stored procedure from my database.</p>
  <p>This button insert I made works well.</p>
  <pre><code>private void btnAdd_Click(object sender, EventArgs e)
  {
          SqlConnection con = new SqlConnection(dc.Con);
          SqlCommand cmd = new SqlCommand(&quot;Command String&quot;, con);
          
          da.InsertCommand = new SqlCommand(&quot;INSERT INTO tblContacts VALUES (@FirstName, @LastName)&quot;, con);
          da.InsertCommand.Parameters.Add(&quot;@FirstName&quot;, SqlDbType.VarChar).Value = txtFirstName.Text;
          da.InsertCommand.Parameters.Add(&quot;@LastName&quot;, SqlDbType.VarChar).Value = txtLastName.Text;
  
          con.Open();
          da.InsertCommand.ExecuteNonQuery();
          con.Close();
  
          dt.Clear();
          da.Fill(dt);
      } 
  </code></pre>
  <p>This is the start of the button that calls the procedure named <code>sp_Add_contact</code> to add a contact. The two parameters for <code>sp_Add_contact(@FirstName,@LastName)</code>. I searched on google for some good examples but found nothing interesting.</p>
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
          SqlConnection con = new SqlConnection(dc.Con);
          SqlCommand cmd = new SqlCommand(&quot;Command String&quot;, con);
          cmd.CommandType = CommandType.StoredProcedure;
  
          ???
          
          con.Open();
          da. ???.ExecuteNonQuery();
          con.Close();
  
          dt.Clear();
          da.Fill(dt);
      }
  </code></pre>