Re: Writing update back to MSAccess table?

Tech-Archive recommends: Fix windows errors by optimizing your registry



My guess is that the query is actually wrong. The code here is solid
(with the exception of maybe a using statement on the command, but that's a
minor oversight, as well as the fact that you should parameterize this
query). You don't have to do a flush or anything, the provider will take
care of everything.

Are you sure that the tblSettings table has a row where the value of the
setting column is "remainreward"?

If so, then can you provide a complete example (along with mdb file)?


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"planetthoughtful" <planetthoughtful@xxxxxxxxx> wrote in message
news:1158893567.670671.154890@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All,

I'm building a Windows Form application that will use a Microsoft
Access mdb file as a data store.

I have a section of code that is executed when the main form is closed
that _should_ update a setting value in a table in my mdb file. The
code executes without any error, but the value in the table appears
unchanged when I open up the table in the mdb file. I call this
function in the FormClosed event of the app's main form.

Code for the function is below:

private void fnSetRewardRemain()
{
using (OleDbConnection conn = new
OleDbConnection(ConnString)){
string thisval = "20";
string CommandString = "UPDATE tblSettings SET
settingval = '" + thisval + "' WHERE setting = 'remainreward'";
OleDbCommand remcom = new OleDbCommand(CommandString,
conn);
remcom.Connection.Open();
remcom.ExecuteNonQuery();
remcom.Dispose();
conn.Close();
}
}

In the example I'm attempting to write the 'hard coded' value of '20'
back to the table. If I write the value of CommandString out to the
console, and manually run it as a query in the mdb file itself, it
works fine. I'm assuming that I'm supposed to do something to 'flush'
the update back to the database, but I'm not sure what. If it helps,
the mdb was created in Acc2003 and is the 2002-2003 compatible file
structure.

Can anyone help me figure out how to get the update to write back to
the actual database?

Many thanks in advance,

pt




.



Relevant Pages

  • Re: Programmatically link tables
    ... "Marshall Barton" wrote: ... by using them in a query with the desired type of Join. ... to an existing backend database. ... link to ANOTHER mdb file that contains table. ...
    (microsoft.public.access.formscoding)
  • Re: Programmatically link tables
    ... by using them in a query with the desired type of Join. ... to an existing backend database. ... link to ANOTHER mdb file that contains table. ... this split database, and the concept of "linked" tables are here: ...
    (microsoft.public.access.formscoding)
  • Re: A really really simple report
    ... To be on the safe side, close the database, close access, then in windows ... shift key, double-click your MDB file. ... You should now see the database window, with 'Open' 'Design' and 'New' ... (Create query in design view and Create query using wizard) ...
    (microsoft.public.access.gettingstarted)
  • Re: Delete multiple mdb database fields & export 1 remaining field as plain text
    ... it works for multi-table queries (and the tables don't even have to be ... than creating a link via code, in order to run a query? ... (where Groups is the name of the table in the external database (and ... Create a permanent dummy mdb file with the query. ...
    (microsoft.public.access.macros)
  • Conversion Access MDB to ADP & MSDE 2000
    ... The prototype MDB file uses DAO, recordsets, & custom functions ... or MTD report on up to 4 buckets/metrics of the data. ... criteria for the underlying report's query. ... Since I haven't used a separate back end database before in Access, ...
    (comp.databases.ms-access)