Return a DataSet in a button's click event?

S

Scott Roberts

MounilK said:
this.btnMybtn.Click += new System.EventHandler(this.btnMyBtn_Click);


private DataSet btnMyBtn_Click(object sender, System.EventArgs e)

The click event *requires* the following:
private void btnMyBtn_Click(object sender, System.EventArgs e)
{
DataSet dtsReportData = ShowReport();
return dtsReportData;
}


I am getting the error:-
Method myfrm.btnShowReport_Click(object, System.EventArgs)' does not match
delegate 'void System.EventHandler(object, System.EventArgs)'

I would like the click event of btnMyBtn to return a DataSet.

Return a DataSet to where? The caller (the button component) does not expect
a return value. Where do you expect the DataSet to be "returned" to?
 
M

MounilK

this.btnMybtn.Click += new System.EventHandler(this.btnMyBtn_Click);


private DataSet btnMyBtn_Click(object sender, System.EventArgs e)
{
DataSet dtsReportData = ShowReport();
return dtsReportData;
}


I am getting the error:-
Method myfrm.btnShowReport_Click(object, System.EventArgs)' does not match
delegate 'void System.EventHandler(object, System.EventArgs)'

I would like the click event of btnMyBtn to return a DataSet. How can I do
that?

TIA,
Mounil.
 
B

Benny Raymond

You need to have it return void

What you need to do is inside the event, do what you need to do with the
dataset. if you look at this line:

this.btnMybtn.Click += new System.EventHandler(this.btnMyBtn_Click);

you're setting the event... You're not setting something equal to
something else... Thus, there's no where to return to.
 
M

Mounilk

Hi Benny,
Thanks for your reply.

The error should read:-

Method myfrm.btnMyBtn_Click(object, System.EventArgs)' does not match
delegate 'void System.EventHandler(object, System.EventArgs)'


ShowReport() returns a DataSet. On the click event of
btnMyBtn, I want to pass on the Dataset. Is that posssible to do?
 
B

Benny Raymond

Where do you want to pass the dataset to? Events are functions that
happen because of something, they're not called from somewhere else in
the code (well... they can be, but not in the way other functions are
called, anyway let's not get confused here).

So, it's not possible to return something from an event. If you think
about it, you're clicking on a button - so if you returned, the return
would go to the button click - there's nothing there for data to go to
except your finger on the mouse button, but why would you want a
database injected into your finger? ;)

Basically you should handle what you want to do inside of the event,
either by having the code there, or by calling a function from within
the event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top