Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dataSet Recognition

Status
Not open for further replies.

JamesHanley

Programmer
Jun 16, 2006
57
US
I have A Button That Calls on a form to retreive found information and place it on the DataGrid.

private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Runing Report...This May Take Several Minutes.");
DataSet lstDataSet = new DataSet();
sla.HRDataSet(lstDataSet, cboApps.Text);
dataGrid1.DataSource = lstDataSet.Tables[0];
}

I created a new button, that will export everything found found and put it to an .xls file. But the button doesn't recognize what lstDataSet is. this code below is directly under the button code above, on the same form. how come it doesn't recognize what it is?

private void button2_Click(object sender, System.EventArgs e)
{
lstDataSet.WriteXml("testingexport.xls");
}

How do i make button2 understand what lstDataSet is when it is on another button directly above?

Brent Serio
Just Born Designs
Email: brentaserio@cox.net
Aim: CsCheerios
 
It doesn't recognize what lstDataSet is because you delcared the variable inside of button1_Click. You need to declare lstDataSet outside of any function but inside of your class for other functions to recognize.

example:
Code:
public partial class CheckoutCart : System.Web.UI.UserControl
{

    protected double dTotal = 0.0;
    protected double dTotalA = 0.0;
    protected string strOrderID = "0";
    protected int iOrderID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    (....code cut)
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top