【问题标题】:Why does cs0433 error happen in Unity3D? How can I solve it?为什么 Unity3D 中会出现 cs0433 错误?我该如何解决?
【发布时间】:2019-12-22 22:12:46
【问题描述】:

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

错误 CS0433:“System.Data”中存在类型“IDataReader”,版本 = 2.0.0.0,文化 = 中性,PublicKeyToken = b77a5c561934e089' 和 'Netstandard,版本 = 2.0.0.0,文化 = 中性,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 () {

}

}

【问题讨论】:

    标签: c# android sqlite unity3d


    【解决方案1】:

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

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

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

    【讨论】:

    • 是“IdataReader”数据类型的问题,还是我的变量名的问题?我尝试将所有内容更改为“SqliteDataReader”,但似乎也不起作用。
    猜你喜欢
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 2023-03-28
    • 2020-11-15
    • 2020-03-30
    相关资源
    最近更新 更多