简体   繁体   English

重载解析失败,因为没有可访问的“ ExecuteScalar”接受此数量的参数

[英]Overload resolution failed because no accessible 'ExecuteScalar' accepts this number of arguments

Im pretty new to VB.NET and was wondering how I'd fix this error im getting. 我是VB.NET的新手,我想知道如何解决此错误。

CODE

 Dim sql As String = "SELECT (USER) FROM USER_CONSTANT"
    Dim conn As New SqlConnection(strConn)
    Dim objDR As SqlDataReader
    Dim Cmd As New SqlCommand(sql, conn)
    conn.Open()
    objDR = Cmd.ExecuteScalar(CommandBehavior.CloseConnection)
    While objDR.Read()
        Label7.Text = objDR("USER")

The ExecuteScalar method doesn't expect any parameter. ExecuteScalar方法不需要任何参数。 The CommandBehavior enum could be passed to the ExecuteReader method, so I suppose that your code should be written as 可以将CommandBehavior枚举传递给ExecuteReader方法,因此我想您的代码应编写为

Dim sql As String = "SELECT (USER) FROM USER_CONSTANT"
Using conn = New SqlConnection(strConn)
Using Cmd = New SqlCommand(sql, conn)
    conn.Open()

    Using objDR = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
       While objDR.Read()
          Label7.Text = objDR("USER")
       End While
    End Using
 End Using
 End Using

It is not clear if you expect to receive more than one record from this code. 尚不清楚您是否希望从此代码中收到多个记录。 In case of multiple records returned then note that at every loop you change the content of the Label7.Text with the current USER and your loop ends with the last name displayed 如果返回多个记录,则请注意,在每个循环中,您都使用当前的USER更改Label7.Text的内容,并且循环以显示的姓氏结束

ExecuteScalar does not accept any variables (see documentation ). ExecuteScalar不接受任何变量(请参阅文档 )。 just change the line to objDR = Cmd.ExecuteScalar . 只需将行更改为objDR = Cmd.ExecuteScalar

Just as the error says, there's no overload of ExecuteScalar which accepts that number of arguments. 正如错误所言, ExecuteScalar不会接受任何数量的参数重载。 Or any arguments . 或任何论点 Instead: 代替:

objDR = Cmd.ExecuteScalar()

Or did you mean to use ExecuteReader , since you're intending to loop over the results and a scalar isn't a result set? 还是您打算使用ExecuteReader ,因为您打算遍历结果并且标量不是结果集?

objDR = Cmd.ExecuteReader(CommandBehavior.CloseConnection)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重载解析失败,因为没有可访问的'writealltext'接受此数量的参数 - overload resolution failed because no accessible 'writealltext' accepts this number of arguments 重载解析失败,因为没有可访问的“参数”接受此数量的 arguments - Overload resolution failed because no accessible 'Parameters' accepts this number of arguments 重载解析失败,因为没有可访问的“新”接受此数目的参数 - overload resolution failed because no accessible 'new' accepts this number of arguments VB.NET MVC重载解析失败,因为没有可访问的“创建”接受此数量的参数 - VB.NET MVC Overload resolution failed because no accessible 'Create' accepts this number of arguments 尝试将stringbuilder文本写入批处理文件时,“由于没有可访问的'New'接受此数目的参数,所以过载解析失败” - “Overload resolution failed because no accessible 'New' accepts this number of arguments” when trying to write stringbuilder text into a batch file VBNET重载,因为没有可访问的“ int”接受数字参数 - VBNET Overload because no accessible 'int' accepts number arguments 重载解析失败,因为对于这些参数,没有可访问的“新”是最具体的 - Overload resolution failed because no accessible 'new' is most specific for these arguments 重载解析失败,因为没有可访问的“新”是这些参数最具体的: - Overload resolution failed because no accessible 'New' is most specific for these arguments: 重载解决失败,因为无法使用这些参数调用可访问的“加入” - Overload resolution failed because no accessible 'Join' can be called with these arguments 重载解析失败,因为没有可访问的“ DataBind”最特定于这些参数 - overload resolution failed because no accessible 'DataBind' is most specific for these arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM