我找不到以下解决方案:
代码:
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();**
}
错误:
字段初始值设定项不能引用非静态字段、方法或属性