Re: Writing update back to MSAccess table?
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Sep 2006 23:08:01 -0400
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
.
- Follow-Ups:
- Re: Writing update back to MSAccess table?
- From: planetthoughtful
- Re: Writing update back to MSAccess table?
- References:
- Writing update back to MSAccess table?
- From: planetthoughtful
- Writing update back to MSAccess table?
- Prev by Date: Writing update back to MSAccess table?
- Next by Date: Re: Learning with command-line vs IDE
- Previous by thread: Writing update back to MSAccess table?
- Next by thread: Re: Writing update back to MSAccess table?
- Index(es):
Relevant Pages
|