Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单的SQL更新语句偶尔在MS Access中工作?_C#_Sql_Ms Access - Fatal编程技术网

C# 简单的SQL更新语句偶尔在MS Access中工作?

C# 简单的SQL更新语句偶尔在MS Access中工作?,c#,sql,ms-access,C#,Sql,Ms Access,我遇到的问题是,当我在不同的字段上运行SQL更新时,我的SQL语句中的条件一个产生更改,另一个不产生更改 这不会产生受影响的行: DateTime now = DateTime.Now; OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET end_log=@end_log WHERE profile_id=@profile_id;"); cmd.Parameters.AddWithValue("@profile_id", profi

我遇到的问题是,当我在不同的字段上运行SQL更新时,我的SQL语句中的条件一个产生更改,另一个不产生更改

这不会产生受影响的行:

 DateTime now = DateTime.Now;
 OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET end_log=@end_log WHERE profile_id=@profile_id;");
 cmd.Parameters.AddWithValue("@profile_id", profileID);  // profileID is a string
 cmd.Parameters.AddWithValue("@end_log", now.ToString());  
 OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET closing=true WHERE profile_id=@profile_id;");
 cmd.Parameters.AddWithValue("@profile_id", profileID);
然而,如果我运行此命令,一行将受到影响:

 DateTime now = DateTime.Now;
 OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET end_log=@end_log WHERE profile_id=@profile_id;");
 cmd.Parameters.AddWithValue("@profile_id", profileID);  // profileID is a string
 cmd.Parameters.AddWithValue("@end_log", now.ToString());  
 OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET closing=true WHERE profile_id=@profile_id;");
 cmd.Parameters.AddWithValue("@profile_id", profileID);
我的班次表包含以下字段:

profile_id - Short Text
end_log - Date/Time
closed - Yes/No
您可以假设两个表在两个实例中都包含相同的数据(这是自动加载的,并且只包含一条记录)


有人发现错误吗?

使用OLEDB提供程序时,参数顺序很重要

而不是

OleDbCommand cmd = new OleDbCommand("UPDATE shifts SET end_log=@end_log WHERE profile_id=@profile_id;");
cmd.Parameters.AddWithValue("@profile_id", profileID);  // profileID is a string
cmd.Parameters.AddWithValue("@end_log", now.ToString());  
试一试


将参数添加到
parameters
集合的顺序应该与查询中参数的出现顺序相匹配。

end\u log=@end\u log几乎肯定是问题所在。打印出错误,然后您可能需要对日期格式进行调整。您的第一个查询没有在数据库管理器中更新吗?我觉得我不太明白你的问题。请尝试使用
now
代替
now.ToString()
s,否则我的第一个查询不会更新,而我的第二个查询会更新。Randy我在INSERT INTO语句中使用了完全相同的“now.ToString()”,效果很好。事实上,我只是尝试在end_notes字段中插入一个字符串,因为该字段定义为长文本,但也没有骰子。在这里不知所措。总而言之,这与此有关:能否指定数据类型为DateTime而不是string?类似这样的内容:cmd.AddParameter(“ExpiryDate”,DbType.DateTime,0,ParameterDirection.Input,now);我现在觉得自己像个十足的白痴。它起作用了!我知道,对于使用
表示法的参数,需要设置顺序,但假定
@
表示法绕过了这一点,因为它是命名的。谢谢,谢谢你的帮助!