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

DataTable row data merged when updating the database

4
Hi All,

I have a problem with updating an Access database from a datatable. I have two rows of data in my database at the moment for testing, the first row is an ID number (primary key), the second is a name and the third is a price.

I can get this data out of the database, store it in a datatable in a dataset and display the name in a listbox with the name and price displayed in textboxes.

If I change the data for the second row data in the app, the updates go into the database OK. Then when I make changes to the first row data, I get odd things happening to the data in the database. I basically merges the names into one and puts it in the database. i.e. if the name in row 1 is aaaa and row 2 is bb, If I change row 1 to aaaa1 I now get bbaaa1 in the database.

This only happens if I change the data in row 2 before row 1 data.

As far as I can tell by debugging in the RowUpdating event handler, the data in the rows is correct in the datatable, and there are no errors in the rows.

the code I use for the update is
Expand|Select|Wrap|Line Numbers
  1. adapterProductDetails.Update(dtProductDetails);
It looks like there is some sort of buffer that isn't being cleared out somewhere, but I don't know what I have to do to clear it. Could it be that because I am using an access database that it can't handle multiple updates being sent to it, I am using an access query (stored proc) with parameters for the updates.

Any thoughts?

Thanks
Feb 19 '09 #1
1 1911
Wavey
4
Hi All,

Just a bit more information

I write to the access database with the following code

Expand|Select|Wrap|Line Numbers
  1.  
  2. DataRow editRow1 = ds.Tables["TraderNames"].Rows.Find("1");
  3. DataRow editRow2 = ds.Tables["TraderNames"].Rows.Find("2");
  4. editRow2["TraderName"] = "Bob";
  5. editRow1["TraderName"] = "AAAAAAA";
  6.  
  7. update.Parameters.Clear();
  8. update.Parameters.Add("@TName", OleDbType.Char, 20, "TraderName");
  9. update.Parameters.Add("@TNum", OleDbType.Char, 20, "TraderNum");
  10. update.Parameters.Add("@ID", OleDbType.Char, 20, "TraderID");
  11.  
  12. int numRows = adapter.Update(ds.Tables["TraderNames"]);
  13.  
The Update Query I use is
Expand|Select|Wrap|Line Numbers
  1. UPDATE Traders SET TraderName = [@TName], TraderNum = [@TNum]
  2. WHERE TraderID=[@ID];

Before I do the update the database holds this information

Expand|Select|Wrap|Line Numbers
  1. TraderID    TraderName    TraderNum
  2. 1    David    20
  3. 2    Hamish    11
  4.  
And after I do the update I see this in the Database
Expand|Select|Wrap|Line Numbers
  1. TraderID    TraderName    TraderNum
  2. 1    AAAAAAA    20
  3. 2    BobAAAA    11
  4.  
Where I would expect it to hold
Expand|Select|Wrap|Line Numbers
  1. TraderID    TraderName    TraderNum
  2. 1    AAAAAAA    20
  3. 2    Bob    11
  4.  
As I can see that the data held in the C# DataSet is what I think it should be I assume that it's something to do with access parameters not cleaning up properly in between updates.

Anyone seen anything like this before?
Feb 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mohamed Osman | last post by:
If a bind a data table to a comboxbox as appose to merging the table into a dataset the selectedvalue property does not work consistently On loading of a form: A datatable is created from a...
2
by: VMI | last post by:
How can I dump a datatable into an Access table (which contais exactly the same structure)? Somebody suggested doing this with a dataAdapter. I don't want to run an Insert query for each record (I...
1
by: Mike | last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
1
by: joel | last post by:
hi guys... i am a student, i am studying and i am a newbie in VB.net and i am using SQL Server 2000. I have this datatable which i insert rows (may take up to 2 or more rows because i would...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi, I wonder if anyone can help? I've got a web form (intranet), .net version 1.1. I've got a sub that populates a datatable in a dataset, dependent on a dropdown field selection. This works...
5
by: jehugaleahsa | last post by:
Hello: I am trying to find what is the very best approach to business objects in Windows Forms. Windows Forms presents an awesome opportunity to use DataTables and I would like to continue doing...
0
LoanB
by: LoanB | last post by:
Hey guys need some info here. I am adding, updating and deleting data on a datagrid. I pass the datagrid's datasource (datatable dt) to my data layer. Assuming I have already created and...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.