u3d和sqlite连接实现插入数据了,相信删、改代码
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
但是编译成ios后出错,据高手指点是xcode中数据库路径问题,未解决 很不错 真心顶 说的非常好 不错不错 LZ真是人才 很不错 真心顶 难得一见的好帖
页:
[1]