check dataset for row number

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

What is the correct syntax to check which row in a dataset you are
currently looking at?

I tried this, but it doesn't work :

if (ds.Tables[0].Row == 1)
{

}
 
Mike P said:
What is the correct syntax to check which row in a dataset you are
currently looking at?

This doesn't make sense. The DataSet is just a container for data. It
does not have the concept of a "current row", and you are never "looking at"
a specific row.

Of course, you can use some code or a separate component to extract some
data from a DataSet and present it on screen. That code or separate
component is the one that "knows" which row of the DataSet it is presenting
on screen. But the DataSet itself is completely unaware of that fact. You
cannot ask the question of "which row we are looking at" to the dataset. You
need to ask it to the component that you used for performing the task of
displaying the contents of the DataSet.
 
What is the correct syntax to check which row in a dataset you are
currently looking at?

I tried this, but it doesn't work :

if (ds.Tables[0].Row == 1)
{

}

The rows are nothing more than an array, so the only way there's a concept
of a "current row" is when you define it yourself (in a variable, for
example), in which case you'll know exactly what row you're "on."
 
What is the correct syntax to check which row in a dataset you are
currently looking at?

I tried this, but it doesn't work :

if (ds.Tables[0].Row == 1)
{

}

What do you mean?

Unless you are iterating through a DataSet like this

for(int i=0; i<ds.Table[0].Rows.Count; i++)
{
}

there is no concept of ordinal or cardinal values. And, if you are going
through like this, the row number only tells you where you are in the loop.
It gives you no information about the data in the row.

you are better to look at the primary key value, esp. if you are not using
derived keys *smacks hands with ruler* or some natural key than trying to
figure out what row.

Now that I am off my soapbox, why is the number important? And, more
important, what is the real problem you are trying to solve? If you only
have time to answer one of the questions, the second one is of more value.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
The reason why I need to do this is because I am adding controls to a
panel in a loop, and I need to create spaces in between each control.

this.pnlCharts.Controls.Add(cht);
this.pnlCharts.Controls.Add(new LiteralControl("&nbsp;"));

But using this method doesn't make the controls line up because the
first control in the panel doesn't have a space before it. So what I
was trying to do was to check for the first row in the dataset, and then
add a space before adding the first control.
 
The reason why I need to do this is because I am adding controls to a
panel in a loop, and I need to create spaces in between each control.

this.pnlCharts.Controls.Add(cht);
this.pnlCharts.Controls.Add(new LiteralControl("&nbsp;"));

But using this method doesn't make the controls line up because the
first control in the panel doesn't have a space before it. So what I
was trying to do was to check for the first row in the dataset, and
then add a space before adding the first control.

If merely searching for first row, then set a "global" boolean:

protected bool isFirstRow = true;

Then set to false after you bind the first row using the row data
binding event.

The solutions is potentially a bit kludgy, but to solve a Is first row?
question, it will work fine. It is the UI, after all. ;-)

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top