类'System.Data.SqlClient.SqlCommand'无法编入索引,因为它没有默认属性 [英] Class 'System.Data.SqlClient.SqlCommand' cannot be indexed because it has no default property

查看:80
本文介绍了类'System.Data.SqlClient.SqlCommand'无法编入索引,因为它没有默认属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!



我正在使用vb.net而我的表格加载活动有问题。

它说类'System.Data.SqlClient.SqlCommand'无法编入索引,因为它没有默认属性。



我实例化了我用过的所有类。

cmd代码上有蓝线。

这是我的代码:



Good Day!

I'm using vb.net and I'm having a problem on my Form Load event.
It says Class 'System.Data.SqlClient.SqlCommand' cannot be indexed because it has no default property.

I instantiated all the class that I've used.
There are blue lines on the "cmd" code.
Here's my code:

Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Building", connect.con)
connect.open()
Dim lrd As SqlDataReader = cmd.ExecuteReader()

On Error Resume Next
While lrd.Read()
    Dim x As Integer = 0

    For x = 0 To 199
        If images(x).Name = cmd("PictureBox").tostring Then
            images(x).Location = New Point(cmd("CoordinateX").tostring, cmd("CoordinateY").tostring)
            images(x).Size = New Point(cmd("SizeWidth").tostring, cmd("SizeHeight").tostring)
        End If
    Next
End While

推荐答案

你'重新尝试从SqlCommand-Object(cmd)获取值。你必须从SqlDataReader(lrd)中读取它们。



所以而不是

You're trying to get the values from the SqlCommand-Object (cmd). You have to read them from the SqlDataReader (lrd).

So instead of
cmd("PictureBox").tostring



你有写一下


you have to write

lrd["PictureBox"].tostring



(以及相应的其他地方)



(或者用圆括号代替角度括号 - 我对VB没有任何线索;))


(and accordingly everywhere else)

(or maybe with round brackets instead of angled brackets - I have no clue of VB ;) )


我尝试使用此代码while lrd.Read()读取它。

它工作正常在我的其他项目上,但这次出现了错误。
I tried to read it by using this code "While lrd.Read()".
It worked on my other projects but this time there's an error.


这篇关于类'System.Data.SqlClient.SqlCommand'无法编入索引,因为它没有默认属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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