我的查询有问题
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()(位于Assets / Script / HighScoreGrammarI.cs:73)>>此行位于HighscoreGrammarI中的while查询内