- using UnityEngine;
- using System.Collections;
- using System.Data;
- using Mono.Data.SqliteClient;
- using System;
- public class test : MonoBehaviour {
- string txtname="111";
- string txtip;
- // Use this for initialization
- void Start () {
-
- }
- void OnGUI()
- {
-
- GUI.Label(new Rect(1,1,50,30),"13");
-
- if(GUI.Button(new Rect(160,200,60,60),"asd"))
- {
- InsertInto();
- print("success");
- }
- GUI.TextArea(new Rect(20,100,60,60),"asdasd");
- OpenDB();
-
- }
- public void Awake()
- {
- print(Application.dataPath);
- }
- public void OpenDB()
- {
- string connectionString= "URI=file:play.db";
- IDbConnection dbcon = (IDbConnection) new SqliteConnection(connectionString);
- dbcon.Open();
- IDbCommand dbcmd = dbcon.CreateCommand();
- string strsql = "SELECT name,ip " + " FROM players";
- dbcmd.CommandText = strsql;
- IDataReader reader = dbcmd.ExecuteReader();
- int i=1;
- while(reader.Read()){
- string name = reader.GetString(0);
- string ip = reader.GetString(1);
- GUI.TextArea(new Rect(1,i*80,200,50),"name:"+name+"\nip:"+ip);
- i++;
- }
- reader.Close();
- reader = null;
- dbcmd.Dispose();
- dbcmd = null;
- dbcon.Close();
- dbcon = null;
- }
- public void InsertInto()
- {
- string connectionString= "URI=file:play.db";
- IDbConnection dbcon = (IDbConnection) new SqliteConnection(connectionString);
- dbcon.Open();
- IDbCommand dbcmd = dbcon.CreateCommand();
- txtname = "test5";
- txtip = "asdasd.sdf";
- print(txtname+txtip);
- string strsql = "Insert into players (id,name,ip) VALUES (6,66,666)";
- dbcmd.CommandText = strsql;
- IDataReader reader = dbcmd.ExecuteReader();
-
- reader.Close();
- reader = null;
- dbcmd.Dispose();
- dbcmd = null;
- dbcon.Close();
- dbcon = null;
- }
- // Update is called once per frame
- void Update () {
-
- }
- }
复制代码sqlite 不支持 webplayer
|