Unity connects to the local database sqlite and the unity database sqlite
First, create an sqlite database, remember the file address, copy it to the Assets directory, and suffix the database file to. sqlite. How to Create Baidu sqlite
Then Baidu Mono. Data. Sqlite is a dll file, which needs to be downloaded and stored in the Assets Directory.
Next, create the c # script,
Using UnityEngine;
Using System. Collections;
Using Mono. Data. Sqlite;
Using System. IO;
Public class SQLiteDemo: MonoBehaviour {
String sqlQuery = "create table unity (unity1 int, unity2 int )";
String sqlQuery = "select * from unity ";
// Use this for initialization
Void Start (){
String connectionString = "Data Source =" + Application. dataPath + "/test. sqlite ";
SqliteConnection dbConnection;
DbConnection = new SqliteConnection (connectionString );
DbConnection. Open ();
SqliteCommand dbCommand;
DbCommand = dbConnection. CreateCommand ();
DbCommand. CommandText = sqlQuery;
DbCommand. ExecuteNonQuery ();
SqliteDataReader dbReader;
DbReader = dbCommand. ExecuteReader ();
While (dbReader. Read ())
{
For (int I = 0; I <dbReader. FieldCount; I ++)
{
Debug. Log (dbReader. GetName (I ));
Debug. Log (dbReader. GetValue (I ));
}
}
}
}
Drag to any object to run.