New to ADO.Net - How to make a simple record update

  • Thread starter Thread starter Gaspar
  • Start date Start date
G

Gaspar

I come from the Delphi + ADO programming environment. I used to have
datasets and records and I was very happy. I read about the ADO.NET breaking
changes and they are very interesting, however I'm having trouble with my
first DB application.

Some facts:

- It seems that all updated are cached. If I modify data in a Grid, it isn't
save until I call the Update method.
- I couldn't find a way to know when a binding source changed the status
from Browsing to Editing, so as to know when should I prompt the user "You
are closing the window, but you have unsaved data data. Do you want to
save?"
- The binding source navigator does not have build it save/edit/cancel
buttons. With ADO, the navigator activated the post/cancel buttons when the
current record was being edited.

Any help? I'm feeling kind of lost.
Thanks!
 
Ah, we've discussed this many times in one form or another. We've found that
it's really easiest to get electroshock therapy to erase what you've learned
about ADO classic. ADO.NET and the binding mechanisms used in .NET are very
different. Data binding is, in fact, much more sophisticated and seems to
work better. ADO.NET uses a disconnected approach so the data is fetched
from the query rowset and persisted into a local DataTable one way or
another. In ASP.NET you can populate a DataGridView with a DataReader but
that's another story...
Once the data is in the complex bound control (like a DataGridView) edits
are kept in the control until you use EndEdit or (in some cases) navigate to
another row in the grid. These operations post the change to the local
in-memory DataTable. If you have built a TableAdapter (or the wizards have
built one for you) or setup your own DataAdapter and configured the right
Commands therein, you'll be able to use the Update method to post the
changes to the database. Depending on the database, those changes might not
appear in the DB for some time. With SQL Server it's immediate. With JET and
others, the data is cached locally and sent on to the DB when the system
gets into an idle (bored) state.
I discuss this and a lot more in my books. "ADO and ADO.NET Best Practices"
was written to help transition from COM-based ADO to ADO.NET. My latest
discusses the TableAdapter in more detail.

hth

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
http://betav.com http://betav.com/blog/billva
____________________________________________________________________________________________
 
Back
Top