-
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.....
-
Re: Populate a combo
Try binding the table not the dataset, oUtil.CreateDataSet(sqlquery).Tables[0].
-
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...
-
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.