title: Error: A field initializer cannot reference the non-static field, method, or property
body: <p>I can't find a solution for the following:</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>class ApiData
  
  { SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:\Users\Peter\Documents   \db.sdf;");
  
  SqlCeCommand cmd = null;
      SqlCeDataReader rdr = null;
      public string code()
      {
          conn.Open();
          cmd = conn.CreateCommand();
          cmd.CommandText ="SELECT code FROM Charakter WHERE id=1";
          rdr = cmd.ExecuteReader();
          rdr.Read();
          string selected = rdr.GetString(0);
          conn.Close();
          return (selected);
      }
  class Data{
    ApiData g= new ApiData();
      string vode = **g.code();**
  }
  </code></pre>
  
  <p><strong>Error:</strong> </p>
  
  <blockquote>
    <p>A field initializer cannot reference the non-static field, method, or property</p>
  </blockquote>