Получение данных из SQLite в Unity3D - PullRequest
0 голосов
/ 13 сентября 2018

У меня проблема с моим запросом

HighScoreGrammarI

- получение данных из sqlite

 private void GetGrammarIScore()
    {
        highScores.Clear();

        using (IDbConnection dbConnection = new SqliteConnection(Connection))
        {
            dbConnection.Open();

            using (IDbCommand dbCmd = dbConnection.CreateCommand())
            {
                string select = String.Format("Select Hs_date, Hs_answer, Hs_score from Highscores_data where Hs_stage = 'GrammarI' and Hs_name = (\"{0}\")", Username.text);

                dbCmd.CommandText = select;

                using (IDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        highScores.Add(new HighScore(reader.GetDateTime(0), reader.GetInt32(1), reader.GetInt32(2)));
                    }
                }
            }
        }
    }

- отображение данных с использованием get data void

 private void showGrammarI()
    {
        GetGrammarIScore();
        for (int i = 0; i < highScores.Count; i++)
        {
            GameObject tmpobjec = Instantiate(ScorePrefab);

            HighScore tmpScore = highScores[i];

            tmpobjec.GetComponent<HighscoreScript>().SetScore(tmpScore.Date.ToString(), tmpScore.CorrectAnswer.ToString(), tmpScore.Score.ToString());
        }
    }

HighscoreScript

public GameObject Date;
    public GameObject CorrectAnswer;
    public GameObject Score;

    public void SetScore(string date, string correctanswer, string score)
    {
        this.Date.GetComponent<Text>().text = date;
        this.CorrectAnswer.GetComponent<Text>().text = correctanswer;
        this.Score.GetComponent<Text>().text = score;
    }

HighScore

public DateTime Date { get; set; }

    public int CorrectAnswer { get; set; }

    public int Score { get; set; }

    public HighScore(DateTime date, int correctanswer, int score)
    {
        this.Date = date;
        this.CorrectAnswer = correctanswer;
        this.Score = score;
    }

ОШИБКА ЗДЕСЬ:

InvalidCastException: Невозможно привести тип источника ктип назначения.Mono.Data.Sqlite.SqliteDataReader.VerifyType (Int32 i, тип DbType) Mono.Data.Sqlite.SqliteDataReader.GetDateTime (Int32 i) HighScoreGrammarI.GetGrammarIScore () (в активах / сценариях / HighScoreG):находится внутри запроса while в HighscoreGrammarI

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...