Dropdown

  • Thread starter Thread starter André Almeida Maldonado
  • Start date Start date
A

André Almeida Maldonado

Hey guys, I'm trying to populate a dropdownlist with this code:

cmdCommand.CommandText = "SELECT cliecodi, clienome FROM clientes"

cmdCommand.CommandType = CommandType.Text

dtrReader = cmdCommand.ExecuteReader()

If dtrReader.Read() Then



drpCoReClie.DataSource = dtrReader

drpCoReClie.DataValueField = "ClieCodi"

drpCoReClie.DataTextField = "ClieNome"

drpCoReClie.DataBind()

dtrReader.Close()

End If

But the dropdown doesn't show the first record, shows only the second to the
last record.

WHY?????
 
Hmmm, maybe it's something to do with the datareader being forward only -
perhaps when you check if the datareader reads it processes the first record
to check

When I need to check if a datareader has values I use the syntax:

If dtrReader.hasrows()
do stuff
end if

The hasrows() method is only supported in version 1.1 though.

Joe
 
do not use if dtrReader.Read

you can directly assign the dtrReader to the dropdown as
DropDown.datasource = dtrReader

Regards
Ather Ali
 
Back
Top