title: How to change static string value by another class?
body: <p>I have class <strong>DatabaseObjects</strong> which have public static string fields. I have a <code>filename</code> and <code>ConnectionStringExcel</code> in this class. Code is as-</p>
  <pre><code>class DatabaseObjects
  {
      public static string filename = &quot;&quot;;
      public static string ConnectionStringExcel = @&quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot; +
                                         filename + &quot;; Extended Properties= 'Excel 12.0 Xml;HDR=YES;'&quot;;
  }
  </code></pre>
  <p>I want to set the <code>filename</code> by the <code>OpenDialogBox</code> in <strong>frmStudents</strong> class on button <strong>Import</strong> Click event. And this <code>filename</code> given by user should be added to the <code>ConnectionStringExcel</code>(Which is in other class).</p>
  <p>Code of <strong>frmStudents</strong> Class</p>
  <pre><code> public partial class frmStudents : Form
  {
  private void btnImport_Click(object sender, EventArgs e)
      {
          OpenFileDialog openFileExcel = new OpenFileDialog();
          openFileExcel.Filter = &quot;Excel Files | *.xlsx; *.xls; *.xlsm&quot;;
          openFileExcel.Title = &quot;Select an Excel File&quot;;
          if (openFileExcel.ShowDialog() == DialogResult.Cancel || openFileExcel.FileName.Equals(&quot;&quot;))
              return;
          DatabaseObjects.filename = openFileExcel.FileName;
          using(OleDbConnection connExcel = new OleDbConnection(DatabaseObjects.ConnectionStringExcel))
          {
              string queryExcel = &quot;SELECT * FROM [Six$]&quot;;
              using (OleDbCommand commandExcel = new OleDbCommand(queryExcel,connExcel))
              {
                  connExcel.Open();
              }
          }
      }
  }
  </code></pre>
  <p>When the user select the file in <code>OpenDialogBox</code>,  the <code>filename</code> string get the value correctly. But <code>filename</code> string value is not combining in <code>ConnectionStringExcel</code>. The <code>Data Source</code> value remains empty. How to resolve this?</p>
  <p>If I remove <code>static</code> keyword from <code>filename</code> and <code>ConnectionStringExcel</code>, it is giving error that <strong>filename</strong> <code>A field initializer cannot reference the non-static field</code>. What now?</p>