c# - 输入字符串的格式不正确 - 使用数据库时
问题描述
我正在使用 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 是在给定乐谱的类型中的乐谱已经存在的情况下,因此我可以在需要时替换现有乐谱。
解决方案
推荐阅读
- html - 如何格式化html表格
- julia - 在 for 循环中填充类型为 any 的多维数组
- angular - Angular 功能、共享和核心模块依赖项
- python-3.x - 字典条目的顺序问题
- php - 在 Woocommerce 3 中通过 ajax 提交并在结帐时创建订单
- javascript - 从另一个 javascript 文件调用 javascript 函数并在 atom IDE 中获取引用错误和无效状态错误以及一些警告
- polymer - 聚合物 - 无法单击元素外部的事件以关闭自身
- for-loop - 替换列表中字节的最快方法是什么
Dart Flutter 中的字节数? - python - 如何使用 LightGBM 在 GridSearchCV 的每次迭代中保存每个预测结果
- javascript - 如何确定 div 内的空白空间并向其中添加内容?