thieumao

Ví dụ đọc SQLite trong Unity đơn giản

Jul 23rd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. // Link huong dan: http://answers.unity3d.com/questions/743400/database-sqlite-setup-for-unity.html
  2. using UnityEngine;
  3. using System.Collections;
  4. using Mono.Data.Sqlite;
  5. using System.Data;
  6. using System;
  7.  
  8. public class XuLy : MonoBehaviour {
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.         Debug.Log ("Thieu Mao");
  13.         string conn = "URI=file:" + Application.dataPath + "/PickAndPlaceDatabase"; //Path to database.
  14.         IDbConnection dbconn;
  15.         dbconn = (IDbConnection) new SqliteConnection(conn);
  16.         dbconn.Open(); //Open connection to the database.
  17.         IDbCommand dbcmd = dbconn.CreateCommand();
  18.  
  19.         string sqlQuery = "SELECT value,name, randomSequence " + "FROM PlaceSequence";
  20.         dbcmd.CommandText = sqlQuery;
  21.         IDataReader reader = dbcmd.ExecuteReader();
  22.  
  23.         while (reader.Read())
  24.         {
  25.             int value = reader.GetInt32(0);
  26.             string name = reader.GetString(1);
  27.             int rand = reader.GetInt32(2);
  28.            
  29.             Debug.Log( "value= "+value+"  name ="+name+"  random ="+  rand);
  30.         }
  31.  
  32.         reader.Close();
  33.         reader = null;
  34.         dbcmd.Dispose();
  35.         dbcmd = null;
  36.         dbconn.Close();
  37.         dbconn = null;
  38.     }
  39.    
  40.     // Update is called once per frame
  41.     void Update () {
  42.    
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment