Date: 04/12/06 (C Sharp) Keywords: sql There has to be a better way to do this... private void btnMarket_Click(object sender, EventArgs e) { DataView dvRates = new DataView(dsHospRates.RateData); dvRates.RowFilter = "RateTypeID = 1 AND ProvID = " + cboName.SelectedValue.ToString(); dgRates.DataSource = dvRates; } private void btnContract_Click(object sender, EventArgs e) { DataView dvRates = new DataView(dsHospRates.RateData); dvRates.RowFilter = "RateTypeID = 2 AND ProvID = " + cboName.SelectedValue.ToString(); dgRates.DataSource = dvRates; } private void btnMarket2_Click(object sender, EventArgs e) { DataView dvRates = new DataView(dsHospRates.RateData); dvRates.RowFilter = "RateTypeID = 3 AND ProvID = " + cboName.SelectedValue.ToString(); dgRates.DataSource = dvRates; } What I want to do is instantiate dvRates somewhere higher up in the code, so each time a button is clicked, the data filters simply get changed instead of a new DataView getting instantiated. However, I can't find a single place where I can instantiate it like this. I've tried putting it in the designer, but I can't figure out what reference contains DataView; declaring it as System.Data.DataView, System.Data.SqlClient.DataView, System.Collections.Generic.DataView, and System.Windows.Forms.DataView all fail. Declaring it in Form_Load makes it private to Form_Load, so it's not recognized below (and I don't want to make Form_Load public). Declaring it outside a routine causes it to break because "An object reference is required for the nonstatic field, method, or property 'HospitalRates.dsHospRates.RateData.get' Is there a way to do what I'm trying to do? Thanks. Visual C# 2005 Standard.
|