Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
|
C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2008 aka C# 3.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 March 31st, 2010, 03:54 AM
Authorized User
 
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
Default C#Net2008 Fill LISTBOX With DATASET

Hi Good Guys,

I am learning how to use C#Net2008 to develop Window Application. I was a VB.NET2008 developer. I need your help, Please Help me.

I am encountering 2 problems trying to fill LISTBOX with DATASET and CATCH to display error message.

In the LISTBOX dropdown list instead of displaying CUSTOMERNAME, it displays System.Data.DataViewManagerListItemTypeDescriptor

Here are the Coding to fill LISTBOX with DATASET
Code:
  private void FLoadListBox()
        {
            string strSql  = "Select CustomerID, CompanyName from Customers   order by CompanyName";
            sqlconn = new SqlConnection(connstr);
            sqlconn.Open();
            sqlDA = new SqlDataAdapter(strSql, sqlconn);
            DS = new DataSet("DS");

            try
               {
                DS.Clear();
                DS.CaseSensitive = true;
                sqlDA.Fill(DS,"Cust");

                // fill listbox
                this.listBoxCust.DisplayMember = "CompanyName";
                this.listBoxCust.ValueMember = "CustomerID";
                this.listBoxCust.DataSource = DS;
                sqlconn.Close();
               }
            catch (SystemException MsgException)
               {
            
                }
            
   } 
__________________


Thank you very much.

Have a good day.

Cheers,
Lennie
 
Old March 31st, 2010, 10:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear good Lennie
use the code below.
I guess u'll get where was ur little mistake


Code:
                this.listBoxCust.DisplayMember = "CompanyName";
                this.listBoxCust.ValueMember = "CustomerID";
                this.listBoxCust.DataSource = DS.Tables["Cust"];
                sqlconn.Close();
__________________
Always,
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to fill a dataset from a gridview sigilaea ASP.NET 2.0 Basics 3 July 19th, 2007 03:16 PM
Fill(dataset) or dataset.load() salemkoten SQL Server 2005 1 November 2nd, 2006 11:04 PM
Fill listbox from excel sheet Alcapone C# 2 December 22nd, 2004 04:31 PM
How to fill stored procedure in dataset. jayaraj ADO.NET 4 August 2nd, 2004 02:40 AM





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