Dataset and DataAdapter - Hardcoded

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have the following hardcoded the following (only the relevant code is
shown),
to populate a datagrid. The data loads into the grid as expected



private void LoadData()
{


//THIS CODE WORKS FINE - within this eventhandler
and the dataset and dataadapter are availible in the intellisense

// Dataset dsModify = New Dataset();

// SqlDataAdapter daModify = new SqlDataAdapter();



}


private void btnModify_Click(object sender, System.EventArgs e)
{
//Accept user changes

// PROBLEM - the dsModify and daModify are not availible in intellisense
to allow modifications to be pushed through to the database

// Errors generated are :

1) The type or namespace daModify could not be found
are you missing a using directive or an assembly reference"
2) The name dsModify does not exist in the <class>.<form>
}


I have attempted to put the following code into the public class of the form

private System.Data.SqlClient.SqlDataAdapter daModify

and get an error saying that daModify is never used - however it is used in
LoadData()

Any assistance would be appreciated

Thanks

Christopher
 
Christopher said:
I have the following hardcoded the following (only the relevant code is
shown),
to populate a datagrid. The data loads into the grid as expected

private void LoadData()
{
//THIS CODE WORKS FINE - within this eventhandler
and the dataset and dataadapter are availible in the intellisense

// Dataset dsModify = New Dataset();

// SqlDataAdapter daModify = new SqlDataAdapter();
}


private void btnModify_Click(object sender, System.EventArgs e)
{
//Accept user changes

// PROBLEM - the dsModify and daModify are not availible in intellisense
to allow modifications to be pushed through to the database

// Errors generated are :

1) The type or namespace daModify could not be found
are you missing a using directive or an assembly reference"
2) The name dsModify does not exist in the <class>.<form>
}

I have attempted to put the following code into the public class of the form

private System.Data.SqlClient.SqlDataAdapter daModify

and get an error saying that daModify is never used - however it is used in
LoadData()

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
You need to change this line
//SqlDataAdapter daModify = new SqlDataAdapter();
to
this.daModify = new SqlDataAdapter();

and also you need to add this line to the class declaration
private System.Data.Dataset dsModify;

and change this line
//DataSet dsModify = new Dataset ();
to
this.dsModify = new Dataset();
 
Back
Top