- Home /
Mysql and Unity : reader problem
Hello everyone.
I'm trying to SELECT some values in my DB but Unity tells me my reader is closed ... Do you know how to fix that ?
Thanks for your help :)
Here my select function :
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 += ";";
if (con.State != ConnectionState.Open)
con.Open();
using (con)
{
using (cmd = new MySqlCommand(query, con))
{
rdr = cmd.ExecuteReader();
}
}
} catch (Exception ex) { Debug.Log(ex.ToString()); } finally {}
return rdr;
}
/ ---------- And now How I'm using it --------- / / --------------------------------------------- /
ArrayList attribut = new ArrayList(); attribut.Add("id");
ArrayList parameter = new ArrayList(); parameter.Add("1");
MySqlDataReader reader = GetValueFromTable("user",attribut,parameter);
while (reader.Read())
{
Debug.Log(reader[0]+" "+reader[6]);
}
reader.Close();
Answer by DaveA · Feb 24, 2011 at 05:17 PM
Although I've never used that class, the examples here http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.71).aspx do the '.Open' after the 'new SqlCommand' Perhaps that order is important?
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to get update from database? 1 Answer
MySQL Funktionen Hilfe 1 Answer
MySQL: Seperation with "," when concatenating two strings 1 Answer
Select mesh element 3 Answers