Move to next DataSet row

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

Hi All,

I'm using the following to fill a DataSet:

public void itemSearch(string column, string item)
{
...fill DataSet
}

I want to be able to move to the next and previous rows with:

private void cmdNext_Click(object sender, EventArgs e)
{
BindingContext[ds.Tables[0]].Position += 1;
}

The problem is the DataSet (ds) isn't accessible. I'm a novice here
but thought that since the Dataset method was public I'd be able to
access it.

How can I do that?

Thanks for any insight.
 
Looch,

You should have a field somewhere that the cmdNext_Click method can
access which holds the data source that you are getting the binding context
for. In other words, you should change your design to return an object and
a string (optionally, for the DataMember) which you can use to get the
binding context.
 
Define a protected DataSet ds field at class level (not
inside any method), and when you get back your DataSet, assign it to
this
field.

Peter, could you provide a quick example? I'm not sure what you mean
by field.
 
public class MyClass
{
protected DataSet myDs;

public void GetDataSet ()
{
// your database call to get back DataSet here
myDs=SqlHelper.ExecuteDataSet (myconn, mysproc, myparams);
}

// now "myDs" is visible from any method in your class, once its been
populated and assigned to the "myDs" variable.
}

Peter
 
Back
Top