jeudi 27 août 2015

Read value from SQLite Database and save value in a Variable

I'm having trouble getting some SQLite programming to work in Unity. I have a database with a couple of values and I want to take one of those values and store it as a variable. This is what I have so far:

public IDbConnection _dbc;
public IDbCommand _dbcm;
public IDataReader _dbr;

public string test2 = "";
public int test = 10;

_dbc = new SqliteConnection(_constr);
_dbc.Open();
_dbcm = _dbc.CreateCommand();
_dbcm.CommandText = "SELECT `Name` FROM `Classes` WHERE `HD`='"+test+"'";
_dbr = _dbcm.ExecuteReader();

while( _dbr.Read())
    test2 = _dbr.GetString(0);

print (test2);
_dbr.Close();

I've played around with it a bit, but so far the print reports no change in the value of test2, which is the variable I want to store the SQLite DB value in.

Aucun commentaire:

Enregistrer un commentaire