Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to commit changes to MSSQL from a typed dataset? 1

Status
Not open for further replies.

xpblueScreenOfDeath

Programmer
Sep 1, 2004
87
I'm new to using .net typed dataset. I could not figured out how to commit the changes I made in the typed dataset into the database. For the typed dataset, I created a new dataset through Visual studio and I started to drag and drop the tables from server explorer. I configured it to generate the code for insert, update, delete, select. Am I just completed missed understand the uses of a typed dataset?

The following is a example of trying to insert a record into the telephoneloghdr table. The following code didn't throw any errors, but no records was inserted.
Code:
TelephoneLog ds = new TelephoneLog();

TelephoneLog.TelephoneLogHdrDataTable teleLogHdr = ds.TelephoneLogHdr;
TelephoneLog.TelephoneLogHdrRow teleLogRow = teleLogHdr.NewTelephoneLogHdrRow();

teleLogRow... = ... assign fields

ds.TelephoneLogHdr.AddTelephoneLogHdrRow(teleLogRow);
ds.TelephoneLogHdr.AcceptChanges();
 
try:

Code:
<yourDataAdapterName>.Update(ds);

However, you must remove the AcceptChanges method. If you AcceptChanges before you update, then the dataset will not have any changes to update the actual database with. By calling Update method of the DataAdapter, it will automatically call AcceptChanges anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top