输入字符串的格式不正确 - 使用数据库时

问题描述

我在 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 (将#修改为@)