DataSet basics - How to fill from stored proc?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have a number of ComboBoxes that I need to change the DataSource of based
on user selection. I'm new to working with ADO, so I'm sure this is a very
basic question...

I want to pass in a string to switch on, and create a DataSet from a stored
procedure, like so:

private void GetCboData(string strCbo)
{
string strStoredProc = "";
OleDbConnection cnxOle = new OleDbConnection();
cnxOle.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Application.StartupPath +
@"\myAccessDb.mdb";
switch (strCbo)
{
case "Customer":
strStoredProc = "someStoredProc";
break;
case "Something Else":
strStoredProc = "someOtherStoredProc";
break;
case "Another Thing"
strStoredProc = "anotherStoredProc";
break;
}
OleDbCommand cmdOle = new OleDbCommand(strStoredProc, cnxOle);
OleDbDataAdapter daOle = new OleDbDataAdapter(cmdOle);
DataSet ds = new DataSet();
daOle.Fill(ds); //<<==== ??????? throws exception
this.cboProductColor.DataSource = ds;
}

How do I fill the DataSet in this scenario?

Thanks in advance.


.



Relevant Pages

  • Re: Need ODBC Jump Start
    ... Depends on what you need exactly and how good you know ADO ... any visual components that will show data, and i would suggest to use a ... TADODataset and Datasource. ...
    (borland.public.delphi.database.ado)
  • Re: Using ADO with data from a binary file
    ... > But some are custom binary files that I need to parse. ... it there a way to bind an array of structures to db-control? ... DataSource to bind to any control that takes a 'datasource'. ... ADO, you would create a "Datasource" that would provide data just like ADO. ...
    (microsoft.public.vb.database.ado)
  • Re: is reset datasource of bound combobox possible?
    ... > 2) Both comboboxes have separate arraylists as their datasource. ... > contains 3 tab pages, one of which contains the comboboxes. ... I notice combobox 2's DisplayValueChanged event fires ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: ComboBox in User Control
    ... This behavior is expected if you try to set same object as datasource ... You should Clone ... DataTable when you change a value in one of the comboBoxes, ... HTH. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: ComboBox in User Control
    ... Dim states as DataTable = getStatesList ... I'm assuming copy does the samething as the clone with the for each row ... > and then assign it as the datasource. ... > DataTable when you change a value in one of the comboBoxes, ...
    (microsoft.public.dotnet.framework.windowsforms.controls)