Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2005, 01:57 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dropdownlist Values From Database

I'm having troubles generating values from a table (database) on to the dropdownlist control. DataSet = "dropdownlist". Your help is greatly appreciated. Thank you all in advance.

My code are as follows:

try
            {
                Database database = new Database();
                OracleConnection connection = database.RHRD();
                string sql = "SELECT PROG_ID FROM SPOOL_CONTROL";
                connection.Open();
                OracleCommand command = new OracleCommand(sql,connection);
                OracleDataReader reader = command.ExecuteReader(System.Data.CommandBehavior. CloseConnection);

                if(reader.HasRows)
                {
                    DataSet.DataSource = reader;
                    DataSet.DataBind();
                }
                else
                {
                    Response.Write("Database is not available!");
                }
            }
            catch(Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
            DataSet.Items.Insert(0,"Choose from list!");
            DataSet.SelectedIndex = 0;
            }

 
Old September 7th, 2005, 02:01 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would like to note that the database connection works, but the values displayed on the dropdownlist looks funky. It shows "System.Data.Common.DbDataRecord".

 
Old September 7th, 2005, 03:06 PM
Registered User
 
Join Date: Aug 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem solved. I forgot to add DataSet.DataValueField = "PROG_ID"; and DataSet.DataTextField = "PROG_ID"; to the code. Thanks all.






Similar Threads
Thread Thread Starter Forum Replies Last Post
2 field Values within DropDownList.DataValueField rit01 ASP.NET 2.0 Basics 4 May 11th, 2016 03:22 AM
Bind DropDownList with null values jwiedmier BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 January 9th, 2008 02:19 AM
Passing values from dropdownlist sparc ASP.NET 1.0 and 1.1 Basics 2 October 31st, 2005 09:42 AM
Dropdownlist Database Connection MBDesktop General .NET 6 December 22nd, 2004 11:01 PM
datagrid dropdownlist values mlwallin ASP.NET 1.0 and 1.1 Professional 0 July 8th, 2003 06:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.