Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 October 19th, 2004, 01:44 PM
Authorized User
 
Join Date: Jun 2004
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to hlchuah77
Default DropDownList with DataReader

According to Wrox book, the authour has mentioned that using data readers is the most efficient way to fetch data directly. So I try to bind the data to my DropDownList using data readers instead of DataSet, but I could't get the desire result.

My coding is as below:

void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            DDList.DataSource = GetEmployeeID();
            DDList.DataBind();
        }
    }

System.Data.SqlClient.SqlDataReader GetEmployeeID()
    {
        string connectToSqlServer = "server=(local);database=Northwind;" +
            "integrated security=true;";

        System.Data.SqlClient.SqlConnection DatabaseConnection =
            new System.Data.SqlClient.SqlConnection(connectToSqlSe rver);

        string queryCommand = "select EmployeeID from Employees order by EmployeeID ASC";

        System.Data.SqlClient.SqlCommand dbCommand =
            new System.Data.SqlClient.SqlCommand();
        dbCommand.CommandText = queryCommand;
        dbCommand.Connection = DatabaseConnection;

        DatabaseConnection.Open();

        System.Data.SqlClient.SqlDataReader myDataReader =
            dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection);

        return myDataReader;
    }


So, what is the mistake at the coding? One thing is that in Wrox book, it never mention the use of System.Data.SqlClient.SqlDataReader, I add it as a test (I don't know whether this is the syntax that actually exist or otherwise).






Similar Threads
Thread Thread Starter Forum Replies Last Post
datareader in c# ryan.thomson C# 6 June 30th, 2009 12:48 AM
regarding datareader adityamadisetty VB.NET 1 May 8th, 2006 09:31 AM
Datareader NitinJoshi ADO.NET 4 January 31st, 2005 08:34 AM
datareader surapongmax ADO.NET 1 October 8th, 2004 07:53 AM
DataReader cjcd BOOK: Beginning ASP.NET 1.0 2 March 21st, 2004 01:06 PM





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