我创建了一个返回 mysql 数据读取器的方法。
public class DbHelper : BaseService
{
public DbHelper(string connectionString) : base(connectionString)
{ }
public static MySqlDataReader GetDataReader(string query)
{
using (MySqlConnection connection = new MySqlConnection(_connectionString))
{
connection.Open();
using (MySqlCommand command = new MySqlCommand(query, connection))
{
MySqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
}
}
}
接下来我写了:
var query = ""; //here my query string
var rdr = DbHelper.GetDataReader(query);
while (rdr.Read())
{
}
但我在这一行收到一个空引用异常return reader;
_connectionString
并query
得到正确的估价。
我该如何解决?我究竟做错了什么?