从字符串 "" 到类型 Double 的转换无效

时间:2021-06-18 10:08:22

标签: asp.net sql-server visual-studio

我收到此错误:

<块引用>

System.InvalidCastException:从字符串 "" 到类型 'Double' 的转换无效。 ---> System.FormatException: 输入字符串的格式不正确。
在 Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) 在 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) --- 内部异常堆栈跟踪结束 --- 在 Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) 在 Microsoft.VisualBasic.CompilerServices.Operators.CompareObject2(Object Left, Object Right, Boolean TextCompare) 在 Microsoft.VisualBasic.CompilerServices.Operators.CompareObjectEqual(Object Left, Object Right, Boolean TextCompare)

我已经尝试过 SQL 语句并且它已经正常工作了。字段“goals1”和“goals2”被定义为 int 和“tipp1”和“tipp2”定义为 varchar(50) 。我试图将目标转换为字符串没有用,也尝试将提示转换为 int 并且它也没有用。这就是代码:

Private Sub mdlCalculate()
            Try
                Dim _sql As String = "SELECT DISTINCT username FROM fly_tippspiel_tipps"
                Dim _dt As DataTable = cData.getDataTable(_sql, 5, GetCurrentMethod.Name, ControlName)

                If _dt.Rows.Count < 1 Then Exit Sub

                _sql = "DELETE FROM fly_tippspiel_ranking"
                cData.exeNonQuery(_sql, 5, GetCurrentMethod.Name, ControlName)

                For Each _row As DataRow In _dt.Rows
                    _sql = "SELECT Table1.goals1, Table1.goals2, Table1.result1, Table1.tipp1, Table1.tipp2, Table1.result2," & _
                        " ISNULL(Table2.iCount,0) AS iCount" & _
                        " FROM (" & _
                            " SELECT fly_tippspiel_games.id, fly_tippspiel_games.goals1, fly_tippspiel_games.goals2, fly_tippspiel_games.result AS result1," & _
                            " fly_tippspiel_tipps.tipp1, fly_tippspiel_tipps.tipp2, fly_tippspiel_tipps.result AS result2" & _
                            " FROM fly_tippspiel_games" & _
                            " INNER JOIN fly_tippspiel_tipps ON fly_tippspiel_games.id = fly_tippspiel_tipps.games_id" & _
                            " WHERE (fly_tippspiel_tipps.username = '" & _row("username") & "')" & _
                            " AND (NOT (fly_tippspiel_games.goals1 IS NULL))) AS Table1" & _
                        " FULL JOIN" & _
                            " (SELECT fly_tippspiel_games.id, COUNT(fly_tippspiel_games.id) AS iCount" & _
                            " FROM fly_tippspiel_games" & _
                            " INNER JOIN fly_tippspiel_tipps ON fly_tippspiel_games.id = fly_tippspiel_tipps.games_id" & _
                            " WHERE goals1 = tipp1 AND goals2 = tipp2" & _
                            " GROUP BY fly_tippspiel_games.id) AS Table2" & _
                        " ON Table1.id = Table2.id" & _
                        " WHERE NOT Table1.goals1 IS NULL"
                    Dim _dt1 As DataTable = cData.getDataTable(_sql, 5, GetCurrentMethod.Name, ControlName)

                    Dim _sum As Integer = 0
                    For Each _row1 As DataRow In _dt1.Rows
                        If _row1("goals1") = _row1("tipp1") And _row1("goals2") = _row1("tipp2") And _row1("iCount") = "1" Then
                            _sum = _sum + 5     ' alleiniges genaues Ergebnis
                        ElseIf _row1("goals1") = _row1("tipp1") And _row1("goals2") = _row1("tipp2") Then
                            _sum = _sum + 3     ' genaues Ergebnis
                        ElseIf _row1("result1") = _row1("result2") Then
                            _sum = _sum + 1     ' Trend
                        End If
                    Next

                    _sql = "INSERT INTO fly_tippspiel_ranking (username, points) " & _
                           "VALUES ('" & _row("username") & "', " & _sum & ")"
                    cData.exeNonQuery(_sql, 5, GetCurrentMethod.Name, ControlName)
                Next
            Catch ex As Exception
                cData.exMessage(ex.ToString, GetCurrentMethod.Name, ControlName)
            End Try
        End Sub

0 个答案:

没有答案
相关问题