DataSet / DataTable SQL Updates

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
 
D

David Browne

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
 
W

William \(Bill\) Vaughn

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.
__________________________________
 
C

Cor Ligthert

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
 
M

Miha Markic [MVP C#]

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! ;-)
 

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