Unity connects to local database SQLite

Source: Internet
Author: User
Tags sqlite database

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.