title: A parameter is missing. [ Parameter ordinal = 1 ]?
body: <p>I've written some basic code to parse a CSV file and input the data into a database at runtime. Variations of this code (for different delimiters and columns) have been working fine for numerous csv files, however for some reason now this code is giving me an error for a 2-column file.</p>
  
  <pre><code>using (StreamReader reader = new StreamReader(@"C:\Rawdata\Salesman.csv"))
  {
      string line;
      StringBuilder query = new StringBuilder();
  
      while (!reader.EndOfStream)
      {
          line = reader.ReadLine();
          StringBuilder segment = new StringBuilder();
  
          for (int i = 0, segno = 0; i &lt; line.Length; i++)
          {
              if (line[i] != '\t')
              {
                  segment.Append(line[i]);
              }
              else
              {
                  switch (segno)
                  {
                      case 0:
                          cmd.Parameters.Clear();
                          cmd.Parameters.AddWithValue("@code", segment.ToString());
  
                          break;
                      case 1:
                          cmd.Parameters.AddWithValue("@name", segment.ToString());
                          break;
                      default:
                          break;
                  }
                  segno++;
                  segment.Clear();
              }
          }
  
          delCmd = "INSERT INTO sales_codes (code, name) VALUES (@code, @name)";
          cmd.CommandText = delCmd;
  
          cmd.ExecuteNonQuery();
  
          query.Clear();
      }
  }
  </code></pre>
  
  <p>The exception being thrown is:</p>
  
  <pre><code>SqlCeException - A parameter is missing. [ Parameter ordinal = 1 ]
  </code></pre>
  
  <p>I've double and triple checked everything from the file, the code to the table schema and all looks well. What am I missing?</p>