如何解决输入字符串的格式不正确 - 使用数据库时
我在 c# 中使用 xamarin,它使用一个包含用户列表的数据库,每个用户都有一个最高分的列表。我正在尝试使用新分数更新分数列表,如下所示:
public score Getscore(DatabaseReference reference)
{
score score = new score();
score.time = TimeSpan.ParseExact(reference.Child("Time").ToString(),@"hh\:mm\:ss\.fffffff",CultureInfo.InvariantCulture);
score.rightAnswers = int.Parse(reference.Child("Right Answers").ToString());
score.genre = reference.Child("Genre").ToString();
return score;
}
public async Task UpdateActivity(string username,score score)
{
User user = await GetUser(username);
DatabaseReference reference = GetDatabase().GetReference("Users").Child(user.userId);
if (score != null)
{
if (await CheckIfscoreExists(username,score) == true)
{
string id = await GetExistingscoreId(username,score);
DatabaseReference scoreRef = reference.Child("scores").Child(id);
score existingscore = Getscore(scoreRef);
if (score.IsHigher(existingscore))
{
reference.Child(id).RemoveValue();
HashMap newscore = new HashMap();
newscore.Put("Genre",score.genre);
newscore.Put("Time",score.time.ToString());
newscore.Put("Right Answers",score.rightAnswers);
reference.Child("scores").Push().SetValue(newscore);
}
}
else
{
HashMap newscore = new HashMap();
newscore.Put("Genre",score.genre);
newscore.Put("Time",score.time.ToString());
newscore.Put("Right Answers",score.rightAnswers);
reference.Child("scores").Push().SetValue(newscore);
}
}
但是当我运行应用程序并尝试更新它时,它说“输入字符串的格式不正确。”关于 rightAnswers 属性。我该如何解决?
注意:函数 GetExistingscoreId 是在给定乐谱类型的乐谱已经存在的情况下,如果需要,我可以替换现有的乐谱。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。