title: Using SqlCommand with C# Variables
body: <p>This is probably a somewhat remedial question, but I'm currently looking to update our database with content from an XML file created in and run through Visual Studio, and I'm fairly certain of what my mistake is, but not how to correct it. Working with Fields field0-field12, this is what I have for each of them.</p>
  
  <pre><code>string strField0; //strField0 - strField12
  var doc = XDocument.Load("serializer.xml");
  
  foreach (var xe in doc.Root.Elements("UserReportPreviewListDto"))
  {
      XElement field0 = xe.Element("Field0");
      ConvertField(xe, "Field0", TranslateValueField);
      if (field0 != null)
      {
          strField0 = field0.Value;
      }
  }
  //strField0 - strField12
  </code></pre>
  
  <p>Below, I call the <code>SqlConnection</code> and <code>SqlCommand</code> thusly.</p>
  
  <pre><code>SqlConnection conn = new SqlConnection();
  conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  string update =
      "INSERT INTO [dbo].[TABLE] ([Code], [Description], [SendEmail], [Type], [CustomForeColor], Inactive], [ModifiedDate], [CreatedDate], [ModifiedById], [CreatedById], [StartDate], [EndDate])
      VALUES (strField1, strField2, strField3, strField4, strField5, strField6, strField7, strField8, strField9, strField10, strField11, strField12)";
  SqlCommand upd = new SqlCommand(update, conn);
  conn.Open();
  upd.ExecuteNonQuery();
  </code></pre>
  
  <p>I'm sure my mistake is in trying to use variables declared in Visual Studio in the Values field of that SQL statement, but I'm not quite sure of what the best workaround for that would be. Additionally, when it comes time to call <code>SqlCommand upd</code>, I'm not sure I'm doing that properly with <code>upd.ExecuteNonQuery();</code>.</p>
  
  <p>I hope I'm clear on what I'm asking for with this. If not, please let me know. Any kind of assistance would be greatly appreciated.</p>