我正在处理 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();
using 块在此处关闭连接(退出时)
using (mysqlCommand = new MySqlCommand(query, mysqlConnection))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)