[英]Why does cs0433 error happen in Unity3D? How can I solve it?
I try to compile my game on Unity, using SQLite as my database.我尝试在 Unity 上编译我的游戏,使用 SQLite 作为我的数据库。 But on the console this error message appears:但是在控制台上会出现此错误消息:
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'错误 CS0433:“System.Data,版本 = 2.0.0.0,Culture = Neutral,PublicKeyToken = b77a5c561934e089”和“Netstandard,Version = 2.0.0.0,Culture = Neutral,PublicKeyToken = cc7b151ffcdd”中存在类型“IDataReader”
How can I solve this?我该如何解决这个问题?
follow my code below按照我下面的代码
PS: sorry for the bad English I am using google translator 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 () {
}
} }
you named IDataReader as a your method however it is already part of System.Data's interface.您将IDataReader命名为您的方法,但它已经是 System.Data 接口的一部分。 You can check more information about IDataReader from microsoft site您可以从微软网站查看有关 IDataReader 的更多信息
https://docs.microsoft.com/tr-tr/dotnet/api/system.data.idatareader?view=netframework-4.8 https://docs.microsoft.com/tr-tr/dotnet/api/system.data.idatareader?view=netframework-4.8
for your problem you just change the name of IDataReader to anything else.对于您的问题,您只需将IDataReader的名称更改为其他任何名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.