Jay1b Posted May 17, 2005 Posted May 17, 2005 (edited) Filling a DROPDOWN box Could someone please review my code and tell me why i keep getting an error whilst trying to fill the DROPDOWN box? Thanks. 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 MyConnection As String = "Host=grppc03;Database=bobbert::mv2;User Id=magic;PWD=password;" Dim IngresConnection As New IngresConnection(MyConnection) IngresConnection.Open() Dim CmdString As String = "SELECT * FROM adjust_stock_t" Dim IngresCommand As New IngresCommand(CmdString, IngresConnection) Dim dr As IngresDataReader dr = IngresCommand.ExecuteReader(CommandBehavior.CloseConnection) 'ddstore is the dropdown box ddStore.DataSource = dr 'Error at this line! ddStore.DataBind() End Sub Edited May 17, 2005 by Jay1b Quote
michael_hk Posted May 17, 2005 Posted May 17, 2005 I usually assign a DataTable to the dropdown box's datasource property instead of a DataReader. Quote There is no spoon. <<The Matrix>>
Jay1b Posted May 17, 2005 Author Posted May 17, 2005 (edited) Yeah i've tried that as well using the following code: 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 MyConnection As String = "Host=grppc03;Database=bobi2::magicv2;User Id=magicdev;PWD=vedjik;" Dim IngresConnection As New IngresConnection(MyConnection) IngresConnection.Open() Dim CmdString As String = "SELECT store FROM inventory_t" Dim IngresCommand As New IngresCommand(CmdString, IngresConnection) Dim dt As New DataTable Dim IAdaptor As New IngresDataAdapter iAdaptor.SelectCommand = IngresCommand IAdaptor.Fill(dt) ddStore.DataSource = dt ddStore.DataBind() End Sub Unfortunately i just get a dropdown box full of 'System.Data.DataViewRow' for each record. Edited May 17, 2005 by Jay1b Quote
Jay1b Posted May 17, 2005 Author Posted May 17, 2005 Just found out i needed to define the datatextfield. Got it now, thanks. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.