DropDown not populating?


G

Guest

Doing the simple DropDown List binding using the method NextResult()
But its just not populating ..
what am i missing
Its populating the 3 DropDwonList but no Data?


Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
Dim sqlConnection As SqlConnection = New SqlConnection
sqlConnection.ConnectionString =
ConfigurationSettings.AppSettings("northwind")
sqlConnection.Open()
Dim sqlCommand As SqlCommand = New SqlCommand
sqlCommand.Connection = sqlConnection
sqlCommand.CommandText = "SELECT ProductName FROM
Products;SELECT CompanyName FROM Shippers;SELECT LastName FROM Employees"

Dim sqlReader As SqlDataReader
sqlReader = sqlCommand.ExecuteReader
DropDownList1.DataSource = sqlReader
DropDownList1.DataValueField = "ProductID"
DropDownList1.DataTextField = "ProductName"
DropDownList1.DataBind()

sqlReader.NextResult()

Dropdownlist2.DataSource = sqlReader

DropDownList1.DataValueField = "ShipperID"
DropDownList2.DataTextField = "CompanyName"
DropDownList2.DataBind()

sqlReader.NextResult()

Dropdownlist3.DataSource = sqlReader
DropDownList1.DataValueField = "EmployeeID"
DropDownList3.DataTextField = "LastName"
DropDownList3.DataBind()
sqlReader.Close()
sqlConnection.Close()
End If
End Sub
 
Ad

Advertisements

B

Brock Allen

This works as expected. The thing odd about your code is that your select
statement is only pulling back one column for each of the SQL statements
but you're trying to access two different columns for your DDLs - one for
ProductName and the other for ProductID. You should add ProductID, ShipperID
and EmployeeID to your column lists in the SQL.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top