在Access中更新数据时出现问题 [英] Problem with updating data in Access

查看:83
本文介绍了在Access中更新数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用另一个表更新表,这样当一个表不包含值时,另一个表会更新。

我正在使用的查询是:

I am updating a table using another table such that when one table doesn''t contain a value the other table is updated.
The Query that I am using is:

Update History set Termination_date = ''date'', Termination_time = ''time'', Link_Status=''1'' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)



当通过ACCESS使用时,查询的工作方式就像魔术一样,但是当它像这样嵌入时:


When used via ACCESS the Query works like magic but when it is embedded like this:

string Date1 = System.DateTime.Now.ToShortDateString();
            string Time1 = System.DateTime.Now.ToLongTimeString();
            string DateTime1 = Date1 + " " + Time1;
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Database\\aharchi.mdb";
            OleDbConnection conn = new OleDbConnection(connStr);
            OleDbCommand com = new OleDbCommand();
            conn.Open();
            com.Connection = conn;
            com.CommandText = "Update History set Termination_date = ''Date1'', Termination_time = ''Time1'', Link_Status=''1'' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)";
            com.ExecuteNonQuery();
            conn.Close();



代码不能像预期的那样工作。请让我知道该怎么做



我真的很抱歉所有!!!!问题被确定来自程序的另一部分而不是这件


the code doesn''t work like it''s intended. Please let me know what to do

I am really sorry ALL!!!! The problem was identified to be from another part of the program not this piece

推荐答案





(...)代码没有像预期的那样工作(...)



可能是因为:



Hi,

(...) the code doesn''t work like it''s intended (...)

Probably because:

string Date1 = System.DateTime.Now.ToShortDateString();
string Time1 = System.DateTime.Now.ToLongTimeString();
string DateTime1 = Date1 + " " + Time1;
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\Database\\aharchi.mdb";
OleDbConnection conn = new OleDbConnection(connStr);
OleDbCommand com = new OleDbCommand();
conn.Open();
com.Connection = conn;
com.CommandText = "Update History set Termination_date = '" + Date1 + "', Termination_time = '" + Time1 + "', Link_Status='1' WHERE Name NOT IN (SELECT NAME FROM IP_State_Down)";
com.ExecuteNonQuery();
conn.Close();





用粗体注意代码。



祝你好运。



Pay attention to the code with bold.

Good luck.


这篇关于在Access中更新数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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