473,378 Members | 1,447 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,378 software developers and data experts.

DataSet Update 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 14696
Hi!

Try removing the line

ds.AcceptChanges();

Since you do this before update the changes made to the dataset will not be
stored in the database.

//Mikael

"Shahar" <sh****@log-on.com> wrote in message
news:e8**************************@posting.google.c om...
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 #2

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

Similar topics

8
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
4
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes,...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
7
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
4
by: jay | last post by:
I am using the dataset object to add a row to a sql server database in vb.net code, as follows: dim drow as DataRow dim cmdBld as new SqlCommandBuilder(mySqlDataAdapter) ds.tables(0).NewRow()...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
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...
4
by: Al | last post by:
I have this scenario: 1. XML file with schema and data is created from SQL Server tables. XML file contains 6 tables, some of them have rows, some of them are empty. 2. XML file is given to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.