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.