无法将类型为"System.Decimal"的对象转换为类型为"System.Data.SqlClient.SqlDataReader" [英] Unable to cast object of type 'System.Decimal' to type 'System.Data.SqlClient.SqlDataReader'

查看:104
本文介绍了无法将类型为"System.Decimal"的对象转换为类型为"System.Data.SqlClient.SqlDataReader"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在犯错.

这是什么..

无法将类型为"System.Decimal"的对象转换为类型为"System.Data.SqlClient.SqlDataReader"."

代码在下面
--------------

Hi,

I am getting below erroe.

what is this..

"Unable to cast object of type ''System.Decimal'' to type ''System.Data.SqlClient.SqlDataReader''."

Code is below
--------------

Function FindLoad(ByVal WeekNo As Integer, ByVal year As Integer, ByVal Empid As Integer, ByVal ProjectCode As String) As Decimal
        Dim Conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MPP").ConnectionString)
        Dim Cmd As New System.Data.SqlClient.SqlCommand
        Dim Rdr As System.Data.SqlClient.SqlDataReader
        Dim Qry As String
        Qry = ""
        Conn.Open()
        Qry = "select isnull(val,0) as value from WeeklyLoad where WeekPeriod=" & WeekNo & " and YearPeriod =" & year & " and Emp_number =''" & Empid & "'' and ProjectCode =''" & ProjectCode & "'' "
        Cmd.Connection = Conn
        Cmd.CommandText = Qry
        Rdr = Cmd.ExecuteScalar
        If Rdr.HasRows Then
            While Rdr.Read
                FindLoad = Rdr("value")
            End While
        Else
            FindLoad = ""
        End If
        Rdr.Close()
        Conn.Close()
    End Function



什么是错误...?



what is the Error...?

推荐答案

Change
Rdr = Cmd.ExecuteScalar


Rdr = Cmd.ExecuteReader


这篇关于无法将类型为"System.Decimal"的对象转换为类型为"System.Data.SqlClient.SqlDataReader"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆