473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataAdapter update - not working

Hi
Why this code does not updated the DB, just the DataSet:

DataSet ds = new DataSet();

OleDbDataAdapte r adapter = new OleDbDataAdapte r("Select * from
Employees", @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=My.mdb") ;
adapter.Fill(ds , "Employees" );

ds.Tables["Employees"].Rows[0].BeginEdit();
ds.Tables["Employees"].Rows[0]["name"] = "X";
ds.Tables["Employees"].Rows[0].EndEdit();

ds.AcceptChange s();
adapter.Update( ds, "Employees" );

foreach(DataRow row in ds.Tables["Employees"].Rows)
{
Console.WriteLi ne(row["id"] + " " + row["name"]);
}
}
catch(Exception exp)
{
Console.WriteLi ne(exp.Message. ToString());
}
Nov 15 '05 #1
1 11997
Get rid of ds.AcceptChange s();

AcceptChanges commits changes to the dataset. All added and modified rows
become "Unchanged" , and, when you call Update (..), the data adapter doesn't
find any modified rows to update. Update () calls AcceptChanges ()
internally.

Hope this helps,

Eliyahu

"Shahar" <sh****@log-on.com> wrote in message
news:e8******** *************** ***@posting.goo gle.com...
Hi
Why this code does not updated the DB, just the DataSet:

DataSet ds = new DataSet();

OleDbDataAdapte r adapter = new OleDbDataAdapte r("Select * from
Employees", @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=My.mdb") ;
adapter.Fill(ds , "Employees" );

ds.Tables["Employees"].Rows[0].BeginEdit();
ds.Tables["Employees"].Rows[0]["name"] = "X";
ds.Tables["Employees"].Rows[0].EndEdit();

ds.AcceptChange s();
adapter.Update( ds, "Employees" );

foreach(DataRow row in ds.Tables["Employees"].Rows)
{
Console.WriteLi ne(row["id"] + " " + row["name"]);
}
}
catch(Exception exp)
{
Console.WriteLi ne(exp.Message. ToString());
}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4240
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third underline. It was working fine before. ConnectionString in Web.config: ----------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <configuration>
1
2311
by: mivey4 | last post by:
Okay, The problem is that I have an Access Database that has the following fields: EmpID - Autonumber (PrimaryKey) AccountID - Text IssueReported - Memo DateOpened - Date/Time TimeOpened - Date/Time
2
2112
by: johnb41 | last post by:
I have a very simple application where i just want to display records from a database, and be able to edit the records. Here's the code for the "update" button: Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click DA.Update(DataSet, "mytable") End Sub
4
11156
by: George | last post by:
Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges(). Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and call the following method. public void JobListDataTableFromAccessCommitChange() { System.Data.DataTable oChangeDataTable;
2
4568
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
5
2931
by: Emil | last post by:
I've created a very simple data base in Microsoft Access 2003. It consists of only one table called "Students" and it contains 2 information about each student: id-student and name. When I try to manipulate data in database I get an error, here's a sample: OleDbConnection connection; connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\ecdl.mdb");
3
2343
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Fill(dataSet, "POI_Entity"); DataRow dataRow = dataSet.Tables.NewRow(); dataRow = 1; dataRow = dataSet.Identity.POI_Entity_ID; dataRow = dataSet.Identity.Chain_ID;
0
1944
by: mcasey0827 | last post by:
I'm writing a little app to get data from a CSV file generated everyday by a vendor and insert it into a Table in our SQL Server database. I can get the data fine, and I can easily merge it with another dataset I pull from the existing table (which is exactly the same except for an Identity Column as PK). When I call SqlDataAdapter.Update, no error is generated, but it makes no changes as well. I have one row present in the Database and...
2
2890
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the following exception: Incorrect syntax near ','. Must declare scalar variable "@ContactID". Here's the code: private void btnSave_Click (object sender, EventArgs e) { DataRow row = dataTable.Rows ; ...
2
3875
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.