"EOF" in Data table

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

Guest

Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm wondering
how you can determine when you get to the EOF in a data table. This is what
I've done below. It works, but I don't think it's the most elegant way of
doing it. How is this normally done? Am I thinking the totally wrong way for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}
 
Ant said:
Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm
wondering
how you can determine when you get to the EOF in a data table. This is
what
I've done below. It works, but I don't think it's the most elegant way of
doing it. How is this normally done? Am I thinking the totally wrong way
for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}
Found this quote from Carsten Thomsen in a quick Google on the subject:

<quote>
In a DataTable you the Rows Collection and the Count property of this
collection to indicate if any rows were returned. The disconnected layer of
ADO.NET, which means classes such as DataSet and DataTable, don't have the
notion of a cursor and therefore you don't have a pointer to a specific row
as you did in ADO. Basically, you can access any row in a DataTable using an
indexer, DataTable.Rows[0] for the first row, DataTable.Rows[1] for the next
row, and so on.
</quote>

Hope this helps.
 
Thanks very much for your response. It tells me what I understand of the
datatable, in that it doesn't have a cursor as such.

But for example, if you are using i++ to access the 'next' row, is there a
property that returns a value indicating that the 'next' ro doesn't exist
(apart from the error raised)

Thanks for any thoughts on this

pvdg42 said:
Ant said:
Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm
wondering
how you can determine when you get to the EOF in a data table. This is
what
I've done below. It works, but I don't think it's the most elegant way of
doing it. How is this normally done? Am I thinking the totally wrong way
for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}
Found this quote from Carsten Thomsen in a quick Google on the subject:

<quote>
In a DataTable you the Rows Collection and the Count property of this
collection to indicate if any rows were returned. The disconnected layer of
ADO.NET, which means classes such as DataSet and DataTable, don't have the
notion of a cursor and therefore you don't have a pointer to a specific row
as you did in ADO. Basically, you can access any row in a DataTable using an
indexer, DataTable.Rows[0] for the first row, DataTable.Rows[1] for the next
row, and so on.
</quote>

Hope this helps.
 
When working with a DataTable Rows collection you iterate through the
collection (as with any collection) using an index (integer) that ranges
from 0 to Rows.Count.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Ant said:
Thanks very much for your response. It tells me what I understand of the
datatable, in that it doesn't have a cursor as such.

But for example, if you are using i++ to access the 'next' row, is there a
property that returns a value indicating that the 'next' ro doesn't exist
(apart from the error raised)

Thanks for any thoughts on this

pvdg42 said:
Ant said:
Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm
wondering
how you can determine when you get to the EOF in a data table. This is
what
I've done below. It works, but I don't think it's the most elegant way
of
doing it. How is this normally done? Am I thinking the totally wrong
way
for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}
Found this quote from Carsten Thomsen in a quick Google on the subject:

<quote>
In a DataTable you the Rows Collection and the Count property of this
collection to indicate if any rows were returned. The disconnected layer
of
ADO.NET, which means classes such as DataSet and DataTable, don't have
the
notion of a cursor and therefore you don't have a pointer to a specific
row
as you did in ADO. Basically, you can access any row in a DataTable using
an
indexer, DataTable.Rows[0] for the first row, DataTable.Rows[1] for the
next
row, and so on.
</quote>

Hope this helps.
 
Perfect. Thank you again
Ant

William (Bill) Vaughn said:
When working with a DataTable Rows collection you iterate through the
collection (as with any collection) using an index (integer) that ranges
from 0 to Rows.Count.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Ant said:
Thanks very much for your response. It tells me what I understand of the
datatable, in that it doesn't have a cursor as such.

But for example, if you are using i++ to access the 'next' row, is there a
property that returns a value indicating that the 'next' ro doesn't exist
(apart from the error raised)

Thanks for any thoughts on this

pvdg42 said:
Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm
wondering
how you can determine when you get to the EOF in a data table. This is
what
I've done below. It works, but I don't think it's the most elegant way
of
doing it. How is this normally done? Am I thinking the totally wrong
way
for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}
Found this quote from Carsten Thomsen in a quick Google on the subject:

<quote>
In a DataTable you the Rows Collection and the Count property of this
collection to indicate if any rows were returned. The disconnected layer
of
ADO.NET, which means classes such as DataSet and DataTable, don't have
the
notion of a cursor and therefore you don't have a pointer to a specific
row
as you did in ADO. Basically, you can access any row in a DataTable using
an
indexer, DataTable.Rows[0] for the first row, DataTable.Rows[1] for the
next
row, and so on.
</quote>

Hope this helps.
 
Hi,

I'm just coming from classic ADO (& still thinking that way) & I'm wondering
how you can determine when you get to the EOF in a data table. This is what
I've done below. It works, but I don't think it's the most elegant way of
doing it. How is this normally done? Am I thinking the totally wrong way for
ADO.NET?

Thanks for any thoughts.

Ant

int i = 0;
private void button1_Click(object sender, System.EventArgs e)
{
daEmployees.Fill(dsEmployees);
try
{
// assuming i is declared elsewhere
i++;
// handle EOF
if(i > dsEmployees.Employees.Rows.Count)
{
return
}
string empName = dsEmployees.Employees.FirstName;
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}

However, IMO, if you fill the DataSet every time the button is clicked
that would be a waste of resources. I would move the Fill method out
of the click event.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
On Sun, 29 Jan 2006 13:53:15 -0600, Otis Mukinfus
Oops!
In line:
// assuming i is declared elsewhere
i++;
// handle EOF

**** oops!
if(i > (dsEmployees.Employees.Rows.Count - 1))
;o)
if(i > dsEmployees.Employees.Rows.Count)
{
return
}
string empName = dsEmployees.Employees.FirstName;
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}

However, IMO, if you fill the DataSet every time the button is clicked
that would be a waste of resources. I would move the Fill method out
of the click event.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com



Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
Hi Otis, thanks for the tip.
Regards
Ant

Otis Mukinfus said:
On Sun, 29 Jan 2006 13:53:15 -0600, Otis Mukinfus
Oops!
In line:
// assuming i is declared elsewhere
i++;
// handle EOF

**** oops!
if(i > (dsEmployees.Employees.Rows.Count - 1))
;o)
if(i > dsEmployees.Employees.Rows.Count)
{
return
}
string empName = dsEmployees.Employees.FirstName;
string empName = dsEmployees.Employees[i++].FirstName;
txtEmpName.Text = empName;
}

catch
{
// do nothing here
}

}

However, IMO, if you fill the DataSet every time the button is clicked
that would be a waste of resources. I would move the Fill method out
of the click event.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com



Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
Back
Top