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


  错误CS0433:类型'IDataReader'存在于'System.Data,版本=
  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 () {

}


}

最佳答案

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

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

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

07-27 13:27