PC Review


Reply
Thread Tools Rate Thread

DataSet basics - How to fill from stored proc?

 
 
deko
Guest
Posts: n/a
 
      12th Jul 2005
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.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      12th Jul 2005
Hi deko,

One more line code is needed:

OleDbCommand cmdOle = new OleDbCommand(strStoredProc, cnxOle);

// add following code
cmdOle.CommandType=CommandType.StoredProcedure;

HTH

Elton Wang
(E-Mail Removed)


"deko" wrote:

> 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.
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent : Populate a dataset from a stored proc in .NET 2.0 John Microsoft ASP .NET 5 20th Feb 2006 03:41 PM
Populating a dataset from a stored proc in .NET 2.0 John Microsoft ASP .NET 0 17th Feb 2006 05:49 PM
Filling a dataset with a stored proc =?Utf-8?B?QW50?= Microsoft ADO .NET 2 8th Feb 2006 01:21 AM
Update using DataSet & Stored Proc. =?Utf-8?B?QVNQIFlhYm9o?= Microsoft ADO .NET 5 7th Oct 2004 04:11 PM
Alias stored proc in dataset? Earl Microsoft ADO .NET 1 3rd Jun 2004 01:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:56 AM.