title: How to refactor an insert stored procedure
body: <p>Just need help taking this big chunk and making it as efficient as possible, I just started learning C# about 2 days ago so still very new to it. But I am writing code that uses an insert stored procedure from my SQL database.</p>
  
  <p>Please also explain why your changes are efficient as well. I just started learning C# so I haven't written anything to connect to the front end of anything, I just thought it'd be cool to be able to write my inputs into the console app and still be able to use a stored procedure. Also one issue that I am facing is that, everything works until i get to the skills input, and it will just skip that part entirely.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data.SqlClient;
  using System.Data;
  
  
  namespace TestConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              using (SqlConnection PubsConn = new SqlConnection("Server=.\\SQLEXPRESS;Database=PeopleDatabase;Trusted_Connection=True;"))
              {
  
  
                  SqlCommand testCMD = new SqlCommand("People_Insert", PubsConn);
  
                  testCMD.CommandType = CommandType.StoredProcedure;
  
                  SqlParameter Id = testCMD.Parameters.Add("@Id", SqlDbType.Int, 5);
                  Id.Direction = ParameterDirection.Output;
                  SqlParameter Title = testCMD.Parameters.Add("@Title", SqlDbType.NVarChar, 100);
                  Title.Direction = ParameterDirection.Input;
                  SqlParameter Bio = testCMD.Parameters.Add("@Bio", SqlDbType.NVarChar, 100);
                  Bio.Direction = ParameterDirection.Input;
                  SqlParameter Summary = testCMD.Parameters.Add("@Summary", SqlDbType.NVarChar, 100);
                  Summary.Direction = ParameterDirection.Input;
                  SqlParameter Headline = testCMD.Parameters.Add("@Headline", SqlDbType.NVarChar, 100);
                  Headline.Direction = ParameterDirection.Input;
                  SqlParameter Slug = testCMD.Parameters.Add("@Slug", SqlDbType.NVarChar, 100);
                  Slug.Direction = ParameterDirection.Input;
                  SqlParameter StatusId = testCMD.Parameters.Add("@StatusId", SqlDbType.Int, 3);
                  StatusId.Direction = ParameterDirection.Input;
                  SqlParameter Skills = testCMD.Parameters.Add("@Skills", SqlDbType.NVarChar, 100);
                  Skills.Direction = ParameterDirection.Input;
                  SqlParameter PrimaryImage = testCMD.Parameters.Add("@PrimaryImage", SqlDbType.NVarChar, 100);
                  PrimaryImage.Direction = ParameterDirection.Input;
  
                  string titleInput;
                  string bioInput;
                  string summaryInput;
                  string headlineInput;
                  string slugInput;
                  int statusId;
                  string skillsInput;
                  string imageInput;
                  string strRowAffect;
  
                  Console.WriteLine("Please Enter a Title");
                  titleInput = Console.ReadLine();
                  Title.Value = titleInput;
  
                  Console.WriteLine("Please Enter a Bio");
                  bioInput = Console.ReadLine();
                  Bio.Value = bioInput;
  
                  Console.WriteLine("Please Enter a Summary");
                  summaryInput = Console.ReadLine();
                  Summary.Value = summaryInput;
  
                  Console.WriteLine("Please Enter a Headline");
                  headlineInput = Console.ReadLine();
                  Headline.Value = headlineInput;
  
                  Console.WriteLine("Please Enter a Unique Slug");
                  slugInput = Console.ReadLine();
                  Slug.Value = slugInput;
  
                  Console.WriteLine("Please Enter a 1 digit Status Id");
                  statusId = Console.Read();
                  StatusId.Value = statusId;
  
                  Console.WriteLine("Please Enter Skills");
                  skillsInput = Console.ReadLine();
                  Skills.Value = skillsInput;
  
                  Console.WriteLine("Enter an Image Url");
                  imageInput = Console.ReadLine();
                  PrimaryImage.Value = imageInput;
  
                  PubsConn.Open();
  
                  strRowAffect = testCMD.ExecuteNonQuery().ToString();
  
                  Console.WriteLine("Number of Rows: " + strRowAffect);
                  Console.WriteLine("Return Value: " + Id.Value);
  
              }
  
              Console.ReadLine();
          }
      }
  }
  </code></pre>