Move to next DataSet row

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
L

Looch

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.
 
G

Guest

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
 

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