用Unity2017.4.2版本開發,封裝一個資料庫管理類 代碼如下
using UnityEngine;
using System;
using System.Collections;
using Mono.Data.SqliteClient;
using System.IO;
// ************************************************************
// 功能:Sqlite資料庫管理類
// ************************************************************
public class DBManager : TF_Singleton<DBManager> {
#region 欄位
private SqliteConnection mConn;
private SqliteCommand mComd;
private SqliteDataReader mReader;
private string mDBPath;
private string mStremingPath;
private string mDBFilePath;
private string mDBName = "Test";
#endregion
#region 方法
void InitDBPath()
{
// 安卓端路徑
mDBFilePath = Application.persistentDataPath + "/" + mDBName;
mDBPath = "URI=file:" + mDBFilePath;
mStremingPath = "jar:file://" + Application.dataPath + "!/assets/" + mDBName;
// 編輯器路徑
if (Application.platform == RuntimePlatform.WindowsEditor)
{
mDBFilePath = Application.streamingAssetsPath + "/" + mDBName;
mDBPath = "Data Source = " + mDBFilePath;
}
}
void Open()
{
if (mConn == null)
{
InitDBPath();
// 第一次在安卓端啟動
if (System.IO.File.Exists(mDBFilePath))
{
WWW www = new WWW(mStremingPath);
while (!www.isDone)
{
}
System.IO.File.WriteAllBytes(mDBFilePath, www.bytes);
}
mConn = new SqliteConnection(mDBPath);
}
mConn.Open();
mComd = mConn.CreateCommand(); //這句這句報錯了 請問該
怎么修改呢?報錯內容為:無法將型別
System.Data.Common.DbCommand隱式轉換為
Mono.Data.SpliteClient.SqliteCommand,存在
一個顯示轉換(是否缺少強制轉換)
}
void Close()
{
if (mConn!=null)
{
// 關閉資料庫
mConn.Close();
}
if (mComd!=null)
{
// 釋放記憶體
mComd.Dispose();
}
}
#endregion
}
uj5u.com熱心網友回復:
mConn.CreateCommand();這句話肯定回傳的是System.Data.Common.DbCommand這個玩意了,然后你接的時候用System.Data.Common.DbCommand這個型別接就行了轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/49011.html
標籤:Unity3D
上一篇:有嘗求個大神做破解手游西游記
