Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VS2010
I have an issue with tableadapter.update not writing to a local access db, which is MS access 2007 mdb. I am working in VS2010 using c#. I am using a strongly typed dataset (XSD).
 
My application draws data into a local db. When I say local, I mean in the sense that I copied the Access DB to the project and the datasource in app.config reflects |Data Directory| as part of it's connection string.
 
I can add rows with out any difficulty, but if I attempt to modify values in an existing row, I don't seem to get that in the underlying database. I have a print/noprint field (defined in access mdb as a Yes/No field) which I want my user to be able to toggle. Yet, the following method doesn't seem to update the underlying table, nor does it throw any errors:
        
private void togglePrintToolStripMenuItem_Click(object sender, EventArgs e)
 
        {
 
            dsH3TableAdapters.lblSourceTableAdapter taLblSource = new dsH3TableAdapters.lblSourceTableAdapter();
 
            taLblSource.FillAll(this.dsH3.lblSource);
 
            dsH3.lblSourceDataTable dtLabels = taLblSource.GetDataAll();
 
 
 
            foreach (dsH3.lblSourceRow rowLabels in dtLabels)
 
            {
 
                bool printingState = rowLabels.bPrintLabel;
 
                rowLabels.BeginEdit();
 
                rowLabels.bPrintLabel = !printingState;
 
                rowLabels.EndEdit();
 
                rowLabels.AcceptChanges();
 
                taLblSource.Update(this.dsH3.lblSource);
 
            }
 

            taLblSource.FillAll(this.dsH3.lblSource);
     }
 
It is possible that I don't fully understand how to use tableadapters and datatables and datarows, but I have done a lot of searching the last few days and a lot of people seem to have this problem with no clearly defined solution.
 
I've tried a variety of beginedit, endedit, acceptchanges, omitting these, etc, to no avail. I can update the rows by calling an update query in the xsd using rowLabels.Order_No and rowLabels.LineNo (which are the primary key fields for the table and defined as such in the XSD), but that is a more time-consuming operation and I would rather make the above work, if I can.
 
I don't think this is an issue with using the local database, I have read the article at MSDN about that, and the fact is my methods to add rows works fine, and all methods that call a query in the xsd work fine. It is just this direct update of the row that doesn't seem to work.
 
I read a post saying this might be a problem if some fields in the db allow nulls, I do allow nulls in some fields.
 
Appreciate any help. Thank you.
Posted 11-Feb-11 4:25am
Comments
Christopher Devous at 15-Feb-11 12:04pm
   
An update, I have read the article on accept changes and eliminated that from the code, but the table adapter update still isn't reflected in the underlying data.
 
If I eliminate the edits and set the field value by executing a table adapter query that updates the current record in the foreach, then the changes are reflected. I am still stumped. Also, I used procmon to verify I am looking at the right db.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have a similar issue, however, I also cannot add rows to database. I can add a row to dataset's table but tableadapter.update does not commit the changes to the database. At the same time tableadapter.insert does work though, i.e. new rows appear in database.
  Permalink  
Comments
Wes Aday at 19-Apr-12 21:47pm
   
And how exactly does this answer the question?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It's just a guess as it's a long time since I used TableAdapters and DataSets, but don't you have to set DataRow.RowState = DataRowState.Modified; before the TableAdapter realises what's going on?
  Permalink  
Comments
Christopher Devous at 11-Feb-11 11:20am
   
Actually, I've checked the rowstate and it does show modified after endedit. Rowstate is readonly.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I realize this is a very old question, but here is the answer for future reference: do NOT call AcceptCancel() before Update()! It will mark the row as Unchanged, and obviously it will not be updated. I agree that the MS documentation is somewhat confusing on this.
 
Vasile
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100