C#Access DB更新行/数据源,AcceptChange不起作用 [英] C# Access DB update row/Datasource with AcceptChange No Work

查看:57
本文介绍了C#Access DB更新行/数据源,AcceptChange不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么不更新Access DB?


字符串Connstr ="Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\ SLTier \\ database31.accdb;";
字符串strSQL ="SELECT * FROM transaction2";

OleDbConnection conn =新的OleDbConnection(Connstr);
OleDbDataAdapter tranAdapter =新的OleDbDataAdapter();
tranAdapter.SelectCommand =新的OleDbCommand(strSQL,conn);
DataSet tranData =新的DataSet();
tranAdapter.Fill(tranData,"transaction2");
DataTable tranTable = tranData.Tables ["transaction2"];

DataRow []找到的行;
foundrows = tranTable.Select(flSL,srtSL);
for(int i = 0; i< foundrows.Length; i ++)
{
//foundrows [i] ["prodatetime"] = DateTime.Now.ToLocalTime();
Console.WriteLine(处理之前:" + foundrows [i] [已处理"] .ToString());
字符串errstr = foundrows [i] .RowState.ToString();
Console.WriteLine("New Rows:" + errstr);
foundrows [i] ["processed"] = true;
foundrows [i] ["prodatetime"] = DateTime.Now.ToLocalTime().ToString();
errstr = foundrows [i] .RowState.ToString();
Console.WriteLine(时间后处理:" + errstr);
Console.WriteLine(后处理:" + foundrows [i] [已处理"] .ToString());
Console.WriteLine(之后的常驻进程:" + foundrows [i] ["resident"].ToString());
Console.WriteLine("Time after time:" + foundrows [i] ["prodatetime"].ToString());
foundrows [i] .AcceptChanges();

预先感谢您的协助!

干杯
RMR

Why isnt the Access DB not being Updated?


string Connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\SLTier\\database31.accdb;";
string strSQL = "SELECT * FROM transaction2";

OleDbConnection conn = new OleDbConnection(Connstr);
OleDbDataAdapter tranAdapter= new OleDbDataAdapter();
tranAdapter.SelectCommand= new OleDbCommand(strSQL,conn);
DataSet tranData = new DataSet();
tranAdapter.Fill(tranData,"transaction2");
DataTable tranTable = tranData.Tables["transaction2"];

DataRow[] foundrows;
foundrows = tranTable.Select(flSL, srtSL);
for (int i = 0; i < foundrows.Length; i++)
{
// foundrows[i]["prodatetime"] = DateTime.Now.ToLocalTime();
Console.WriteLine("Process Before: " + foundrows[i]["processed"].ToString());
String errstr = foundrows[i].RowState.ToString();
Console.WriteLine("New Rows : " + errstr);
foundrows[i]["processed"] = true;
foundrows[i]["prodatetime"] = DateTime.Now.ToLocalTime().ToString();
errstr = foundrows[i].RowState.ToString();
Console.WriteLine("Process after Time: " + errstr);
Console.WriteLine("Process after: " + foundrows[i]["processed"].ToString());
Console.WriteLine("Resident Process after: " + foundrows[i]["resident"].ToString());
Console.WriteLine("Process after Time: " + foundrows[i]["prodatetime"].ToString());
foundrows[i].AcceptChanges();

Thank you in advance for your assistance!

Cheers
RMR

推荐答案

它不起作用,因为您不知道AcceptChanges的用途.尝试将光标放在AcceptChanges上,然后按F1键以了解其实际作用.不要仅仅假设您知道,因为方法的名称很有意义.

顺便说一句:您真正想要的方法称为更新",而不是"AcceptChanges".
It doesn''t work because you have no idea what AcceptChanges is used for. Try putting the cursor on AcceptChanges and hitting F1 to find out what it really does. Don''t just assume you know because the name of the method makes sense.

BTW: The method you really want is called "Update", not "AcceptChanges".


这篇关于C#Access DB更新行/数据源,AcceptChange不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆