我将数据访问层的方法改成了静态方法,然后提示:<o:p></o:p>
对象引用对于非静态的字段、方法或属性“DataAccess.ConnectionString”是必需的
<o:p></o:p>
请问要如何修改?谢谢
public class DataAccess
{
public string ConnectionString = "server=192.168.2.19;User Id=root;password=12!;Database=project_status;Character Set=utf8;";
public static MySqlDataReader GetDataReader(string sql)
{
MySqlDataReader resultReader = null;
MySqlConnection connection = new MySqlConnection(DataAccess.ConnectionString);//此处提示错误
MySqlCommand command = new MySqlCommand(sql, connection);
command.CommandType = CommandType.Text;
connection.Open();
resultReader = command.ExecuteReader(CommandBehavior.CloseConnection);
return resultReader;
}
}