我正在處理C#和MySql請求。我試圖檢索我的數據庫中的數據庫,但我有這個錯誤消息:讀取器關閉時讀取無效嘗試。閱讀器關閉時嘗試讀取無效
感謝您的幫助球員:)
我有這樣的功能:
public MySqlDataReader GetValueFromTable(string table, ArrayList attribut, ArrayList parameter)
{
string query = string.Empty;
MySqlDataReader rdr = null;
try
{
query = "SELECT * FROM `" + table + "` WHERE ";
for (int i = 0; i < attribut.Count; i++)
{
query += attribut[i] as string;
query += " = ";
query += parameter[i] as string;
if(i != attribut.Count - 1)
query += " AND ";
}
query += ";";
using (mysqlConnection)
{
using (mysqlCommand = new MySqlCommand(query, mysqlConnection))
{
rdr = mysqlCommand.ExecuteReader();
}
}
}
catch (Exception ex)
{
Debug.Log(ex.ToString());
}
finally {}
return rdr;
}
而旁邊的地方在我的代碼我這樣做:
ArrayList attribut = new ArrayList();
ArrayList parameter = new ArrayList();
attribut.Add("usern_id");
parameter.Add("1");
MySqlDataReader reader = dataBase.GetValueFromTable("papillon", attribut, parameter);
reader.Read();
Debug.Log(reader[0]);
reader.Close();
如何使用rdr?當連接周圍的使用塊退出時,連接關閉,閱讀器關閉。 – JohnC 2011-04-01 17:47:32
相同的錯誤在不同的場景http://stackoverflow.com/questions/6775136/invalid-attempt-to-call-read-when-reader-is-closed-error-for-lengthy-operatio – Lijo 2012-11-20 04:39:45