title: Why is my C# string not affecting my stored procedures IF statements?
body: <p>I'm using T-SQL and this is one of my stored procedures as you can read, depending on what my parameter (<code>@para_type</code>) is either <code>Employee</code> or <code>Consultant</code>, the following statements will execute and triggers will be upon fired. The stored procedure is working when it's executed in SQL Server Management Studio (SSMS).</p>
  
  <p>Where I enter the following: </p>
  
  <pre><code> execute update_person @para_salary = 800, @para_ssn = 17,
                         @para_companyName = 'Ikea',@para_expdate = '20201230',
                         @para_type = 'Consultant', @para_officeId = 2
  </code></pre>
  
  <p>But then in my C# Winforms code, I use a textbox to fill the  parameter for T-SQL (<code>@para_type</code>). It is not affecting my stored procedure's <code>IF</code> statements. I've debugged it in C# and everything is executed accordingly but my stored procedure won't do what is programmed for.</p>
  
  <p>Stored procedure:</p>
  
  <pre><code>create procedure update_person
      @para_salary varchar(25),
      @para_ssn int,
      @para_companyName varchar(25),
      @para_expdate date,
      @para_type varchar(10),
      @para_officeId int
  as 
  begin
      if @para_ssn is null
          print('Please enter a value for (ssn)')
     else if @para_type = 'Employee'
          delete from consultant 
          where ssn = @para_ssn        
  
     update person 
     set flag = @para_type
     where ssn = @para_ssn
  
     update employee
     set salary = @para_salary
     where ssn = @para_ssn     
  
     if @para_type = 'Consultant'
          delete from employee 
          where ssn = @para_ssn           
  
     update person 
     set flag = @para_type
     where ssn = @para_ssn
  
     update consultant
     set companyName = @para_companyName, expdate = @para_expdate
     where ssn = @para_ssn 
  
     update works_at
     set officeId = @para_officeId
     where ssn = @para_ssn
  end
  </code></pre>
  
  <p>C# Winform the view:</p>
  
  <pre><code>public void initializeComboBoxes()
  { 
       var arr1 = new string[] { "Employee", "Consultant" };
  
       foreach (var item in arr1)
           add_person_combobox.Items.Add(item);
  
       add_person_combobox.SelectedIndex = 0;
  
       foreach (var item in arr1)
           update_person_combobox.Items.Add(item);
  
       update_person_combobox.SelectedIndex = 0;
  }
  
  private void lblTimer(int i)
  {
      var t = new Timer();
  
      t.Interval = i;
  
      t.Tick += (s, e) =&gt;
          {
              ResponseLbl.Text = "";
              t.Stop();
          };
  
      t.Start();
  }
  
  private void update_person_btn_Click(object sender, EventArgs e)
  {
      if (string.IsNullOrWhiteSpace(update_person_salary.Text))
      {
          update_person_salary.Text = "0";
      }
  
      if (string.IsNullOrWhiteSpace(update_person_CoName.Text))
      {
          update_person_CoName.Text = "Lund Consulting AB";
      }
  
      int ssn = Convert.ToInt32(update_person_ssn.Text);            
      string type = update_person_combobox.SelectedItem.ToString();
      int salary = Convert.ToInt32(update_person_salary.Text);
      string comName = update_person_CoName.Text;
  
      int officeId = update_person_officeId.SelectedIndex + 1;
      DateTime expdate = update_person_expDate.Value.Date;
  
      if (ctrl.update_person(salary, ssn, comName, expdate, type, officeId) == true)              
      {                     
          ResponseLbl.ForeColor = System.Drawing.Color.Green;
          ResponseLbl.Text = "Succesfull";
          lblTimer(3000);               
      }
      else
      {
          ResponseLbl.ForeColor = System.Drawing.Color.Red;
          ResponseLbl.Text = "Failed";
          lblTimer(3000);
      }
  }
  </code></pre>
  
  <p>C# data access layer </p>
  
  <pre><code>public bool update_person(int ssn, int salary, string companyName, DateTime expdate, string type, int officeId)
  {
      try
      {
          con.Open();
  
          cmd = new SqlCommand("update_person", con);
          cmd.CommandType = System.Data.CommandType.StoredProcedure;            
  
          cmd.Parameters.AddWithValue("@para_ssn", ssn);
          cmd.Parameters.AddWithValue("@para_salary", salary);
          cmd.Parameters.AddWithValue("@para_companyName", companyName);
          cmd.Parameters.AddWithValue("@para_expdate", expdate);
          cmd.Parameters.AddWithValue("@para_type", type);
          cmd.Parameters.AddWithValue("@para_officeId", officeId);
  
          cmd.ExecuteNonQuery();
          con.Close();
  
          return true;
      }
      catch (SqlException e)
      {
          Console.WriteLine("error: " + e.Message);
          con.Close();
          return false;
      }                      
  }
  </code></pre>