title: Creating SQL Statements from a Text File - C#
body: <p>Good morning, </p>
  
  <p>I´m trying to create a program to create statements in a .Sql document but i´m having some troubles.</p>
  
  <p>this is my code so far:</p>
  
  <pre><code>string[] filas = File.ReadAllLines("c:\\temp\\Statements.txt");
                  StreamWriter sw = new StreamWriter("c:\\temp\\Statements.sql");
                  foreach (string fila in filas)
                  {
                      string sql = "INSERT ";
                      string[] campos = fila.Split(' ');
  
                      if (campos[0]== "1A")
                      {
                          sql += " INTO TABLE1 (field1) VALUES (" + campos[1] + ");";
                      }
                      else
                      {
                          sql += " INTO TABLE2 (field1,field2,field3) VALUES (" + campos[1] + "," + campos[2] + "," + campos[3] + ");";
                      }
                      sw.WriteLine(sql);
                  }
  
                  sw.Close();
                  {
  </code></pre>
  
  <p>the thing is: </p>
  
  <p>I need to read a txt document (the lenght will change), and then transform it to a sql document with all the statements,  there are only two tipes of lines starting in "1A" or "2B", example:</p>
  
  <p><strong>1A123456  456,67
  <br>
  2B123456  mr awesome  great strt   germany
  <br>
  1A123456  456,67
  <br>
  2B123456  mr awesome  great strt   germany
  <br>
  2B123456  mr awesome  great strt   germany
  <br>
  1A123456  456,67
  <br>
  1A123456  456,67</strong></p>
  
  <p>then im trying to "transform" that information on "inserts":</p>
  
  <pre><code>INSERT  INTO TABLE1 (REF,MONEY) VALUES (A123456,456,67);
  INSERT  INTO TABLE2 (REF,NAME,ADR) VALUES (B123456,mr awesome,great strt);
  INSERT  INTO TABLE1 (REF,MONEY) VALUES (A123456,456,67);
  INSERT  INTO TABLE2 (REF,NAME,ADR) VALUES (B123456,mr awesome,great strt);
  INSERT  INTO TABLE2 (REF,NAME,ADR) VALUES (B123456,mr awesome,great strt);
  INSERT  INTO TABLE1 (REF,MONEY) VALUES (A123456,456,67);
  INSERT  INTO TABLE1 (REF,MONEY) VALUES (A123456,456,67);
  </code></pre>
  
  <p>my code is not working so well... i hope someone can help me a litte :).</p>
  
  <p>regards.</p>