gpt4 book ai didi

c# - 为什么Unity3D会出现cs0433错误?我该如何解决?

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:49 25 4
gpt4 key购买 nike

我尝试在 Unity 上编译我的游戏,使用 SQLite 作为我的数据库。但在控制台上出现此错误消息:

error CS0433: Type 'IDataReader' exists in 'System.Data, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = b77a5c561934e089' and 'Netstandard, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = cc7b13ffcd2ddd51'

我该如何解决这个问题?

按照我下面的代码

PS:抱歉我使用谷歌翻译器的英语不好

// Use this for initialization
void Start () {

}

public void OpenDB(string p)
{
Debug.Log("Call to OpenDB:" + p);
// check if file exists in Application.persistentDataPath
string filepath = Application.persistentDataPath + "/" + p;
if(!File.Exists(filepath))
{
Debug.LogWarning("File \"" + filepath + "\" does not exist. Attempting to create from \"" +
Application.dataPath + "!/assets/" + p);
// if it doesn't ->
// open StreamingAssets directory and load the db ->
WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + p);
while(!loadDB.isDone) {}
// then save to Application.persistentDataPath
File.WriteAllBytes(filepath, loadDB.bytes);
}

//open db connection
connection = "URI=file:" + filepath;
Debug.Log("Stablishing connection to: " + connection);
dbcon = new SqliteConnection(connection);
dbcon.Open();
}

public void CloseDB(){
reader.Close(); // clean everything up
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}

public IDataReader BasicQuery(string query){ // run a basic Sqlite query
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
return reader; // return the reader

}


public bool CreateTable(string name,string[] col, string[] colType){ // Create a table, name, column array, column type array
string query;
query = "CREATE TABLE " + name + "(" + col[0] + " " + colType[0];
for(var i=1; i< col.Length; i++){
query += ", " + col[i] + " " + colType[i];
}
query += ")";
try{
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
}
catch(Exception e){

Debug.Log(e);
return false;
}
return true;
}

public int InsertIntoSingle(string tableName, string colName , string value ){ // single insert
string query;
query = "INSERT INTO " + tableName + "(" + colName + ") " + "VALUES (" + value + ")";
try
{
dbcmd = dbcon.CreateCommand(); // create empty command
dbcmd.CommandText = query; // fill the command
reader = dbcmd.ExecuteReader(); // execute command which returns a reader
}
catch(Exception e){

Debug.Log(e);
return 0;
}
return 1;
}

public int InsertIntoSpecific(string tableName, string[] col, string[] values){ // Specific insert with col and values
string query;
query = "INSERT INTO " + tableName + "(" + col[0];
for(int i=1; i< col.Length; i++){
query += ", " + col[i];
}
query += ") VALUES (" + values[0];
for(int i=1; i< col.Length; i++){
query += ", " + values[i];
}
query += ")";
Debug.Log(query);
try
{
dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader();
}
catch(Exception e){

Debug.Log(e);
return 0;
}
return 1;
}

public int InsertInto(string tableName /*, string[] values*/ ){ // basic Insert with just values
string query;
// query = "INSERT INTO " + tableName + " VALUES (" + values[0];
// for(int i=1; i< values.Length; i++){
// query += ", " + values[i];
// }
// query += ")";
query = "INSERT into" + tableName + "VALUES (1,'vini','aa',0)";

try
{
dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader();
}
catch(Exception e){

Debug.Log(e);
return 0;
}
return 1;
}

public ArrayList SingleSelectWhere(string tableName , string itemToSelect,string wCol,string wPar, string wValue){ // Selects a single Item
string query;
query = "SELECT " + itemToSelect + " FROM " + tableName + " WHERE " + wCol + wPar + wValue;
dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = query;
reader = dbcmd.ExecuteReader();
//string[,] readArray = new string[reader, reader.FieldCount];
string[] row = new string[reader.FieldCount];
ArrayList readArray = new ArrayList();
while(reader.Read()){
int j=0;
while(j < reader.FieldCount)
{
row[j] = reader.GetString(j);
j++;
}
readArray.Add(row);
}
return readArray; // return matches
}

// Update is called once per frame
void Update () {

}

最佳答案

您将 IDataReader 命名为您的方法,但它已经是 System.Data 接口(interface)的一部分。您可以从 Microsoft 站点查看有关 IDataReader 的更多信息

https://learn.microsoft.com/tr-tr/dotnet/api/system.data.idatareader?view=netframework-4.8

对于您的问题,您只需将 IDataReader 的名称更改为其他名称即可。

关于c# - 为什么Unity3D会出现cs0433错误?我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57527129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com