This is a simple question, but it is a bit hard for Unity newbie like me.
I have coded this. (See below.)
using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite;
using System.Data;
using System;
public class NewBehaviourScript1 : MonoBehaviour {
// Use this for initialization
void Start () {
string conn = "URI=file:" + Application.dataPath + "/sensor.sqlite"; //Path to database.
IDbConnection dbconn;
dbconn = (IDbConnection) new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT x1 " + "FROM sport";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int value = reader.GetInt32(0);
string name = reader.GetString(1);
int rand = reader.GetInt32(2);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
}
and saved.
However, I do not know how to execute this. Any idea? Thank you.
Aucun commentaire:
Enregistrer un commentaire