title: How to Read/Write to SQL database from console application (C#)
body: <p>I am new to SQL server. </p>
  
  <p>As you can see my first function above is simply used to call the second function and pass a list as a parameter.<br>
  Now I am parsing the info from the dividedTrans char array. 
  Each value means something and this I am displaying to the console. 
  However, I need to save it to an SQL database. The parsed values. 
  I have some experience in SQLite, however this is a bit different. 
  I googled things up and this is what I could come up with. However, I found no simple way to update columns. My column names are the same as what is mentioned in the console.writeline code, for example some of the columns are "data record" , "record_id", "article_code" etc. So I wish to save to column "data record" the value of "2.1 Movement record" for instance and then in "record_id" the value of dividedTrans[0]. Could someone please help me with an efficient way of doing this?</p>
  
  <pre><code>class save_parsed_data
  {
      static string connectionstring;
      static SqlConnection connection; 
  
      public static void save_data(string transaction)
      {
          connectionstring = ConfigurationManager.
                 ConnectionStrings["testEnvironmentSAMPLE.Properties.Settings.sampleConnectionString"].ConnectionString;
  
              List&lt;char&gt; dividedTrans = new List&lt;char&gt;(transaction.ToCharArray());
  
              if (transaction.StartsWith("21"))
                  StringWith21(dividedTrans);
  
              Console.ReadKey();
      }
  
      public static void StringWith21(List&lt;char&gt; dividedTrans)
      {
          using (connection = new SqlConnection(connectionstring))
          using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Sample_values", connection))
          {   
              DataTable codaTable = new DataTable(); 
              adapter.Fill(codaTable);
  
              Console.WriteLine("\nData Record 2.1: Movement Record.");
  
              Console.WriteLine("Record Identification: {0}", dividedTrans[0]);
  
              Console.WriteLine("Article Code: {0}", dividedTrans[1]);
  
              Console.WriteLine("Sequence Number: {0}", new string(dividedTrans.GetRange(2, 4).ToArray()));
  
              Console.WriteLine("Detail Number: {0}", new string(dividedTrans.GetRange(6, 4).ToArray()));
  
              Console.WriteLine("Reference Number of bank: {0}", new string(dividedTrans.GetRange(10, 21).ToArray()));
  
              Console.WriteLine("Movement Sign: {0}", new string(dividedTrans.GetRange(31, 1).ToArray()));
  
              Console.WriteLine("Amount: {0}", Convert.ToString(Int32.Parse(string.Join("", dividedTrans.GetRange(32, 15)))));
  
              Console.WriteLine("Value Date: {0}", DateandTime(string.Join("", dividedTrans.GetRange(47, 6))).ToString("d"));
  
              Console.WriteLine("Transaction Code: {0}", new string(dividedTrans.GetRange(53, 8).ToArray()));
  
              Console.WriteLine("Communication Type: {0}", new string(dividedTrans.GetRange(61, 1).ToArray()));
  
              Console.WriteLine("Communication zone: {0}", new string(dividedTrans.GetRange(62, 53).ToArray()));
  
              Console.WriteLine("Entry Date: {0}", DateandTime(string.Join("", dividedTrans.GetRange(115, 6))).ToString("d"));
  
              Console.WriteLine("Sequence Number: {0}", new string(dividedTrans.GetRange(121, 3).ToArray()));
  
              Console.WriteLine("Globalization Code: {0}", new string(dividedTrans.GetRange(124, 1).ToArray()));
  
              Console.WriteLine("Next Code: {0}", new string(dividedTrans.GetRange(125, 1).ToArray()));
  
              Console.WriteLine("Blank: {0}", new string(dividedTrans.GetRange(126, 1).ToArray()));
  
              Console.WriteLine("Linker Code: {0}", new string(dividedTrans.GetRange(127, 1).ToArray()));
          }
      }
  
  }
  </code></pre>