R
Rui Macdonald
What is wrong with this code to populate a DropDownList?
Can somebody Help me?
Tnx
RMac
=====================================================================================
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.CloseConnection)
While myReader.Read()
'Console.WriteLine(myReader.GetString(0))
DropDownList1.Items.Add(myReader.GetString(0))
End While
myReader.Close()
myConnection.Close()
End Sub
End Class
Can somebody Help me?
Tnx
RMac
=====================================================================================
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.CloseConnection)
While myReader.Read()
'Console.WriteLine(myReader.GetString(0))
DropDownList1.Items.Add(myReader.GetString(0))
End While
myReader.Close()
myConnection.Close()
End Sub
End Class