Results 1 to 4 of 4

Thread: Populate a combo

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Populate a combo

    What i am doing wrong?

    This is a code to populate a combobox.

    Utilitarios oUtil=new Utilitarios();
    sqlquery="Select * from area_caja order by descripcion";
    cboarea.DataSource= oUtil.CreateDataSet(sqlquery);
    cboarea.DisplayMember = "descripcion";

    where CreateDateSet is:

    public DataSet CreateDataSet(string sqlstring)
    {
    Utilitarios oUtil=new Utilitarios();
    cn.ConnectionString = oUtil.GetConnectionstring();
    OleDbCommand Cmd = new OleDbCommand (sqlstring, cn);
    OleDbDataAdapter da = new OleDbDataAdapter(Cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    cn.Close();
    return ds;
    }

    The problem is that the text displayed on the combo is:
    System.Data.....

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Populate a combo

    Try binding the table not the dataset, oUtil.CreateDataSet(sqlquery).Tables[0].

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Populate a combo

    In my last post in this thread, there is something that could fill a combobox, have a look, it may help...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Populate a combo

    I don't get this wide-spread obsession with DataSets. If you are only populating a single DataTable then using a DataSet is pointless. A DataSet is only useful if you have numerous tables, you need to use DataRelations between tables or you need to pass a DataSet to or from a Web service. A DataSet with a single DataTable in it is like an array with a single element, except that the DataSet is much more complex. It doesn't serve any purpose in this case as far as I can tell. Just create and populate a DataTable in your method and assign that to your DataSource.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width