0
votes

I'm kind of new to vb and I wanted to add items to a dropdownlist with datas from my database but I think I got the syntax wrong because I get the 'identifier expected' error.

Here is my code:

    Dim dr As SqlDataReader

    Dim myCommand = New SqlCommand("Select * from Vendeur", con)

    con.Open()
    dr = myCommand.ExecuteReader()


    While dr.Read()
        cboVendeur.Items.Add(dr['NomVendeur'].toString())
        dr.NextResult()
    End While

    con.Close()

Does anyone know what I'm doing wrong?

1
You don't need dr.NextResult(). And: cboVendeur.Items.Add(dr("NomVendeur").toString()) should be the right syntax. - muffi

1 Answers

1
votes

VB.NET uses parentheses, not brackets, for indexing. Also, strings are enclosed in double-quotes, not single-quotes.

The following line:

cboVendeur.Items.Add(dr['NomVendeur'].toString())

should be:

cboVendeur.Items.Add(dr("NomVendeur").toString())