Are you getting an error?
You could just use
dropdownlist1.DataSource = dr
dropdownlist1.DataTextField = "Marca"
dropdownList1.DataBind()
but it'll do the same..null reference? not displaying what you thought it
hsould?
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Rui Macdonald" <ruimacdonald@hotmail.com> wrote in message
news:%23iZUUL3QFHA.2604@TK2MSFTNGP10.phx.gbl...[color=blue]
> What is wrong with this code to populate a DropDownList?
>
> Can somebody Help me?
>
> Tnx
>
> RMac
>[/color]
================================================== ==========================
=========[color=blue]
> WebForm.aspx.vb
>
> Imports System
> Imports System.Data
> Imports System.Data.OleDb
> Imports System.Threading.Thread
> Imports System.Web.UI.WebControls.DropDownList
> Public Class WebForm2
> Inherits System.Web.UI.Page
> Protected WithEvents DropDownList1 As
> System.Web.UI.WebControls.DropDownList
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
> End Sub
>
> #End Region
> Public dbRead
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> 'Put user code to initialize the page here
> Dim sql
> Dim myConnection As New
> OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" &
> Server.MapPath("/db/ProdutosFotografia.mdb"))
>
> sql = "SELECT Distinct Marca FROM Produtos"
> Dim myCommand As New OleDbCommand(sql, myConnection)
> myCommand.Connection.Open()
> Dim myReader As OleDbDataReader =
> myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
> While myReader.Read()
> 'Console.WriteLine(myReader.GetString(0))
> DropDownList1.Items.Add(myReader.GetString(0))
> End While
> myReader.Close()
> myConnection.Close()
> End Sub
> End Class
>
>[/color]