Click here to Skip to main content
15,898,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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
Posted
Updated 25-Feb-15 0:29am
v2

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

So instead of
VB
cmd("PictureBox").tostring

you have to write
VB
lrd["PictureBox"].tostring

(and accordingly everywhere else)

(or maybe with round brackets instead of angled brackets - I have no clue of VB ;) )
 
Share this answer
 
v3
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.
 
Share this answer
 
Comments
[no name] 25-Feb-15 7:28am    
I edited my above solution, please have a look at it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900