473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DataSet problem

Hi what's worng with the following code, the chages I made is only
change the DataSet but not the Data-Base:

try
{
DataSet ds = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from
Employees", @"Provider=Microsoft.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.AcceptChanges();
adapter.Update(ds, "Employees");

foreach(DataRow row in ds.Tables["Employees"].Rows)
{
Console.WriteLine(row["id"] + " " + row["name"]);
}
}
catch(Exception exp)
{
Console.WriteLine(exp.Message.ToString());
}
Nov 15 '05 #1
1 3112
On 10 Aug 2003 00:01:14 -0700, sh****@log-on.com (Shahar) wrote:
Hi what's worng with the following code, the chages I made is only
change the DataSet but not the Data-Base:

try
{
DataSet ds = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from
Employees", @"Provider=Microsoft.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.AcceptChanges();
adapter.Update(ds, "Employees");

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


You are "updating" with the wrong dataset.
Prior to calling the AcceptChanges method, you need to call the
GetChanges method to return a dataset containing only the changed
records (inserted, deleted, or modified). That is the dataset that
Update should be called with, i.e.,

// change some fields...
// now get the changed records and apply them
DataSet changedData = ds.GetChanges();
if (changedData != null)
{
adapter.Update(changedData);
ds.AcceptChanges();
}

Oz
Nov 15 '05 #2

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

Similar topics

6
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
2
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
2
by: theWizK | last post by:
Hello all. I have noticed that when I generate a strongly-typed dataset from an xml schema that the DataTables that are generated have their constructors marked as internal. What this means is...
4
by: Joerg M. Colberg | last post by:
Hi all, I have a problem when using a DataSet. I am using it to query a SQLServer database as follows. In my code it looks like SqlDataAdapter eDA = new SqlDataAdapter(sqlcmd); // where...
2
by: Dennis | last post by:
Hi, I am hoping I can get some help with a small problem I have run into using C#. U have an XML file that I load into a Dataset and then display this in a Datagrid. No problems doing this at all....
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
0
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
2
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
8
by: Harry Strybos | last post by:
Visual Studio 2005 - SP1 - VB.Net on WinXP SP2 I add a typed dataset to my solution and get the following errors : Error 1 sub 'ReadXmlSerializable' cannot be declared 'Overrides' because it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.