Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2006, 11:05 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default update db from dataset

Hi everybody,

i am writing an application that connects to a database with OLEDB objects and i am stuck at the point where i made my changes in my dataset and i want to write back from my dataset to my db. I tried it and my data are can be altered in the dataset but never on the database...

do i update line by line to my database?
do i update with a command the whole dataset?

below is a sample of my code
any ideas or recommendations please tell me



----by clicking the button update the follow commands should run

'check first if the dataset is loaded
If (cmydataset.Tables.Contains("course")) Then

cmyadapter = New OleDb.OleDbDataAdapter("select * from student", cmycon)
'normally here i would have more than one field but i omitted for simplicity reasons
cmyadapter.UpdateCommand = New OleDb.OleDbCommand("Update course set cour_name = Textbox1.text " & _
" WHERE Cour_ID = Textbox2.text")

'check if there are null values
If (TextBox1.Text = "") Then
MsgBox("you have nulls, you cannot enter null values")
Else
'chekc update student constraints
'if ok
'update student data

cmyadapter.Update(cmydataset, "Course")
cmydataset.AcceptChanges()
End If
End If


 
Old July 2nd, 2006, 06:27 PM
Registered User
 
Join Date: Dec 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're supposed to first Accept Changes made to the dataSet, then update the dataAdapter.
It should be working fine if you switch your two last statements:

  cmydataset.AcceptChanges()
  cmyadapter.Update(cmydataset, "Course")





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Dataset Update Aaron Edwards ADO.NET 1 April 29th, 2005 04:26 AM
update access db with dataset DennisGi ASP.NET 1.0 and 1.1 Basics 0 November 8th, 2004 04:43 AM
Dataset Merge then DB Update druid2112 ADO.NET 0 October 4th, 2004 08:44 AM
Dataset Update with Null Value [V] reyboy ADO.NET 2 June 1st, 2004 12:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.