MS Access的更新不坚持...... [英] Updates to MS Access not sticking...
问题描述
您好,我是一段时间以来一直在编写C#中各种版本的Visual Studio代码,但最近升级到Vista SP1作为开发环境的全新办公套件。
< br>我的问题是我对访问数据库所做的更新不坚持。如果我运行我的代码,更新*似乎*成功,甚至到关闭和重新检索数据库中的数据。我甚至可以结束程序并重新运行它,并且更新似乎就在那里。但是,如果我关闭程序,打开Access并检查表,则值将不会更新。如果我然后重新运行我的程序,它会显示旧值。
这是我的代码片段:
public void InsertRow(string connectionString,string insertSQL)
{
using(OleDbConnection connection = new OleDbConnection(connectionString))
{
// insertSQL字符串包含一个SQL语句那个
//在源表中插入一个新行。
OleDbCommand命令= new OleDbCommand(insertSQL);
//将Connection设置为新的OleDbConnection。
command.Connection = connection;
//打开连接并执行insert命令。结果试结果{点击connection.Open();结果,command.ExecuteNonQuery();
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
//当//代码退出using块时,连接自动关闭。
这应该看起来很熟悉,因为我将它从hep文档中复制出来。 :)我的SQL语句恰好是更新而不是插入。知道为什么更新似乎会采取,但......磨损?我假设它与缓存没有被写回来有关,但是丢失了...
David
David
嗨David,
这是一个GAX特定论坛,请将你的问题发布到正确的C#论坛。
http://social.msdn.microsoft.com/forums / EN-US / csharpgeneral /线程/ 搜索结果,由于结果,圣何塞。
Hello,
I have been writing code for some time the various versions of Visual Studio in C#, but recently moved up to Vista SP1 as a development environment with the whole new office suite.
My problem is that updates that i make to an access database don't stick. If I run my code, the update *seems* to be successful, even to the point of closing and re-retrieving the data from the database. I can even end the program and re-run it, and the updates appear to be there. But if i close the program, open Access, and inspect the table, the values are un-updated. If I then rerun my program, it shows the old values.
Here is my code snippet:
public void InsertRow(string connectionString, string insertSQL)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
// The insertSQL string contains a SQL statement that
// inserts a new row in the source table.
OleDbCommand command = new OleDbCommand(insertSQL);
// Set the Connection to the new OleDbConnection.
command.Connection = connection;
// Open the connection and execute the insert command.
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}
This should look familiar because i copied it right out of the hep documentation. :) My SQL statement just happens to be an update rather than an insert. Any idea why the update would appear to take, but... wear off? I am assuming that it is something to do with a cache not being written back, but am lost...
David
David
Hi David,
this is a GAX specific forum, please post your question in the proper C# forum.
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/threads/
thanks
jose.
这篇关于MS Access的更新不坚持......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!