DataSet / DataTable SQL Updates

  • Thread starter Thread starter BILL
  • Start date Start date
B

BILL

Hi Everyone,

I need to know if this is right after about an hour of reasearch
concerning set-based operations against an ADO.NET DataSet or
DataTable.

It looks like MS discourages the use of anything (legacy) concerning
the use of a "current record".. ie, MoveFirst(), MovePrevious(), etc.
in favor of set based operations on a DataSet or DataTable.

From what I've read, we can "SELECT" records from one of the above
objects, but there's no mechanism to "UPDATE" or "DELETE" rows other
than iterating through an array returned by the .Select() method. Is
this right? I understand that a DataSet/DataTable represents a fully
disconnected source of data and why set-based commands would be a
logical step forward, but why only include "SELECT"?

Thanks in advance for any advice at all!
BILL
 
BILL said:
Hi Everyone,

I need to know if this is right after about an hour of reasearch
concerning set-based operations against an ADO.NET DataSet or
DataTable.

It looks like MS discourages the use of anything (legacy) concerning
the use of a "current record".. ie, MoveFirst(), MovePrevious(), etc.
in favor of set based operations on a DataSet or DataTable.

From what I've read, we can "SELECT" records from one of the above
objects, but there's no mechanism to "UPDATE" or "DELETE" rows other
than iterating through an array returned by the .Select() method. Is
this right?

Yes. It really woudn't add much. If you select your target rows and
perhaps sort them using the DataTable's magic select and sort methods,
iterating the target rows only takes two lines of code.

foreach (DataRow r in selectedRows)
{
r[someColumn] = 4;
}

David
 
The Rows collection can be stepped through in any way you would normally
step through a collection. However, you can also address the rows using the
ordinal

myTable.Rows(intOrdinal).Item("MyColumn")

This approach is lighter and faster than the ADO classic Recordset and does
not confuse the developer with the concept of a "current" row pointer that
must be maintained separately and can point "beyond" the rowset (as when BOF
or EOF) is true.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
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.
__________________________________
 
This approach is lighter and faster than the ADO classic Recordset and does
not confuse the developer with the concept of a "current" row pointer that
must be maintained separately and can point "beyond" the rowset (as when
BOF or EOF) is true.

Nice text Bill.

:-)

Cor
 
Yes. It really woudn't add much. If you select your target rows and
perhaps sort them using the DataTable's magic select and sort methods,
iterating the target rows only takes two lines of code.

foreach (DataRow r in selectedRows)
{
r[someColumn] = 4;
}

Hey, those are 4 lines! ;-)
 
Back
Top