Click here to Skip to main content
15,885,031 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
Comments
Christopher Devous 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.

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?
 
Share this answer
 
Comments
Christopher Devous 11-Feb-11 11:20am    
Actually, I've checked the rowstate and it does show modified after endedit. Rowstate is readonly.
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
 
Share this answer
 
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.
 
Share this answer
 
Comments
[no name] 19-Apr-12 21:47pm    
And how exactly does this answer the question?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900