First of all to create a SQLite database, remember the file address, copied to the assets directory, the creation of the database file suffix. sqlite. Specific ways to create Baidu SQLite
Then Baidu Mono.Data.Sqlite, this is a DLL file, download down, also need to put into the assets directory
Next, create a 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 onto any object and run.
Unity connects to local database SQLite