title: How to pass NULL Value to Stored Procedure Through C#
body: <p>I have multiple textboxes and I want to allow the user to leave some empty 
  instead of giving the error </p>
  
  <blockquote>
    <p>SqlParameterCollection only accepts non-null SqlParameter type
    objects.</p>
  </blockquote>
  
  <p>What I use for inserting data  that is in Data_Access_Layer Class</p>
  
  <pre><code>public void ExecuteCommand(string Data, SqlParameter[] param)
      {
          SqlCommand sqlcmd = new SqlCommand();
          sqlcmd.CommandType = CommandType.StoredProcedure;
          sqlcmd.CommandText = Data;
          sqlcmd.Connection = sqlconnection;
  
  
          if (param != null)
          {
  
              sqlcmd.Parameters.AddRange(param);
          }
  </code></pre>
  
  <p>The Main form Code: </p>
  
  <pre><code>namespace M_Weight_System.Presentation_Layer
  {
      public partial class Main : Form
      {
          Bussiness_Layer.Cls_Data dta = new Bussiness_Layer.Cls_Data();
          public Main()
          {
              InitializeComponent();
          }
  
          private void bSave_Click(object sender, EventArgs e)
          {
              try
              {
                dta.Add_Data(tId.Text, tNumber.Text, tClient.Text, tDriver.Text, Convert.ToInt32(tFirst.Text), Convert.ToInt32(tSecond.Text), Convert.ToInt32(rt2.Text), tDate1.Text,tCity.Text, tType.Text,tDate2.Text);
                  MessageBox.Show("Success");
                  bEdit.Enabled = true;
                  NewToolStripMenuItem.Enabled = true;
                  PrintToolStripMenuItem.Enabled = false;
              }
              catch
              {
                  MessageBox.Show("Problem !");
              }
          }
  
          private void bEdit_Click(object sender, EventArgs e)
          {
              try
              {
                  dta.Update_Data(tId.Text, tNumber.Text, tClient.Text, tDriver.Text, Convert.ToInt32(tFirst.Text), Convert.ToInt32(tSecond.Text), Convert.ToInt32(rt2.Text), tDate1.Text, tCity.Text, tType.Text, tDate2.Text);
                  MessageBox.Show("Success");
  
              }
              catch
              {
                  MessageBox.Show("Problem !");
              }
  
          }
          }
  }
  </code></pre>