Hi All Masters

I'm trying to create a form with multiple labels from mysql database, im confused to add newlabel text from records
here's my code

 Dim str As String
        str = " Select koderoom from room "
        da = New MySqlDataAdapter(str, conn)
        ds = New DataSet
        da.Fill(ds, "room")
        For i = 1 To ds.Tables("room").Rows.Count
            Dim newLabel As New Label
            newLabel.Name = "Label" & i
            **newLabel.Text = newLabel.Name**
            newLabel.BorderStyle = BorderStyle.FixedSingle
            newLabel.Size = New Drawing.Size(100, 100)

            If (i = 1) Then
                newLabel.Location = New Point(20, 20)
                newLabel.Location = New Point(20 * i + ((i - 1) * newLabel.Width), 20)
            End If



When I run the above code, the label text is show " label1, label2.....
I want to dislay label text from database records
What am I missing? Any suggestions as to how to fix this?

In Advance , Thanks for the help


Ps: I'm Using Visual Studio 2010 Express

In advance, thanks for any help.

newLabel.Text = newLabel.Name

Inspite of this code at line no 9 to show data from table you can use this following codes

newLabel.Text = ds.Tables("room").Rows(i)(ColumnIndex)


new Label.Text=ds.Tables("room").Rows(i)("Column Name")

Hope it can help you

hi shark 1

as you suggestion i use this code

newLabel.Text = ds.Tables("room").Rows(i)("koderoom")

it show error


is any another advice for me ...??
thanks for your help

Edited 1 Year Ago by Imam_3: edited

@Imam_3: Sorry! I overlooked the codes for the Loop.

In vb.net any collection of objects are always 0 base indexed. So to count the total item numbers is always 1 less from the upper bound of that specific collection i.e Collection.count-1. If you have a collection of 10 objects. The index of the first element should be 0 and the index of the Last element should be Collection.Count-1 i.e. 10-1=9. So loop always rotates between 0 to Collection.Count-1
So your loop should be

For i = 0 To ds.Tables("room").Rows.Count-1

'your codes here


Hope it can help you.


owwwhhh...i'm sorry for that ...yes it must be Rows.Count -1 ...i forgot that ..hehehe

BTW your code is OK...finnaly it's show records...
thank's for your help..



This question has already been answered. Start a new discussion instead.