我正在建立一个网站,当我点击某个特定按钮时,它会显示数据或状态。但是当我单击它时,会出现将数据类型varchar转换为数字的错误。
这是我的代码
for
非常感谢
这是我的GetDataSet2的代码
Dim ds As New DataSet
Try
ds = GetDataSet2("dateadd(mm, datediff(mm, 0, last_check), 0) as DateMonthly, SUM((convert(decimal(5,2), left(duration, 3))))/count(*) as AverageMonthly", "tblServices_Status AS TSES, tblWeb_Apps as TWA", "TSES.web_apps_id = TWA.web_apps_id AND TWA.web_apps_id = '" & appid & "' AND MONTH(last_check) = MONTH(dateadd(dd, -1, GetDate())) AND YEAR(last_check) = YEAR(dateadd(dd, -1, GetDate()))", "dateadd(mm, datediff(mm, 0, last_check), 0)", "dateadd(mm, datediff(mm, 0, last_check), 0)")
For Each dr As DataRow In ds.Tables(0).Rows
lblAppAveMonthly.Text = Format(Val(dr("AverageMonthly")), "0.00") + "s"
Next
Catch ex As Exception
Throw ex
Finally
ds.Dispose()
End Try
答案 0 :(得分:0)
我看到导致此错误的唯一可能的候选人是:
SUM((convert(decimal(5,2), left(duration, 3))))/count(*) as AverageMonthly
在duration
列中查询无法将前3个字符转换为小数(5,2)数据类型的任何行。
如果你有SQL Server 2012或更高版本,那么TRY_PARSE()函数在这里非常有用。