Why wont the Drop down list show data

Alien10140

New Member
Hi ,<BR><BR>I am using a Drop down list in asp.net ( editor VS.NET ) Lang = VB.<BR><BR>Now i am using the code behind tactic to create a connection in the Page_Load Sub <BR><BR>and then in the Drop Down List Databindings Sub binding the data to the control .<BR><BR>Here is the code i have so far as explained above.<BR><BR>Imports System<BR>Imports System.Data<BR>Imports System.Data.SqlClient<BR>Public Class WebForm1<BR><BR> Inherits System.Web.UI.Page<BR> Protected WithEvents DDLP As System.Web.UI.WebControls.ListBox<BR> Dim objDR As SqlClient.SqlDataReader<BR> Dim myCommand2 As New SqlClient.SqlCommand(strSQL2, myConnection2)<BR> Dim myConnection2 As New SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SCon.ConnectionString"))<BR> Const strSQL2 As String = "SELECT *" & _<BR> "From Phase ORDER BY Phase "<BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR><BR> '1. Create a second connection<BR> Dim myConnection2 As New SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SCon.ConnectionString"))<BR><BR> '2. Create the command object, passing in the SQL string<BR> Const strSQL2 As String = "SELECT Phase" & _<BR> "From Phase ORDER BY Phase "<BR> Dim myCommand2 As New SqlClient.SqlCommand(strSQL2, myConnection2)<BR><BR> '3. Create the DataReader<BR> myConnection2.Open()<BR><BR> Dim objDR As SqlDataReader<BR> objDR = myCommand2.ExecuteReader(CommandBehavior.CloseConn ection)<BR><BR> End Sub<BR><BR>Private Sub DDLP_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLP.DataBinding<BR><BR> objDR = myCommand2.ExecuteReader(CommandBehavior.CloseConn ection)<BR><BR> ' Binding the data to the control<BR> DDLP.DataSource = objDR<BR> DDLP.DataBind()<BR> End Sub<BR><BR>Now my problem is this :<BR><BR>a. I dont know if this is the most efficiant way of geting data from a SQL DB into a Drop down list.<BR>B. How afficiant is my code?<BR>C. when i run the page the page runs BUT there is nothing in the control ( no data from the fields specified in the SQL query)<BR><BR>?????????????????????????????????????????????????? ???????????????<BR><BR>ANy help and why is there no data?<BR><BR>Thank you any help would be greatly appreciated!<BR><BR>Carlos<BR>Please mail me at [email protected]<BR><BR>
 
Back
Top