|
-
Feb 3rd, 2006, 07:41 AM
#1
Thread Starter
Fanatic Member
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.....
-
Feb 3rd, 2006, 07:49 AM
#2
Fanatic Member
Re: Populate a combo
Try binding the table not the dataset, oUtil.CreateDataSet(sqlquery).Tables[0].
-
Feb 5th, 2006, 10:17 PM
#3
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...
-
Feb 5th, 2006, 10:24 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|