首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

.net + Access 一个非常非常非常奇怪的有关问题!达人进

2012-03-15 
.net + Access 一个非常非常非常奇怪的问题!达人进!asp.net + Access,很简单,却很诡异,数据表结构:表[wc_s

.net + Access 一个非常非常非常奇怪的问题!达人进!
asp.net + Access,很简单,却很诡异,数据表结构:
表 [wc_subject]
字段 sub_id 自动编号
字段 sub_amount 整型 默认 0
字段 sub_date 日期 默认 now()

asp.net执行.传参如下:

"@sub_date" , DateTime.Now;
"@sub_id", 1

其它不变,SQL语句和执行情况:

A:
update wc_subject set sub_amount=sub_amount+1, sub_date=@sub_date where sub_id=@sub_id
执行结果: 未执行

B:
update wc_subject set sub_amount=sub_amount+1 where sub_id=@sub_id
执行结果:成功

C:
update wc_subject set sub_amount=sub_amount+1, sub_date=@sub_date where sub_id=1
执行结果:成功

D:
update wc_subject set sub_date=@sub_date where sub_id=@sub_id
执行结果:未执行


结论:貌似@sub_date和@sub_id不能同时在一起?好几年前就发现这问题,只是后来一直改为SQL Server,也就没深究,最近突然又想起,想问问达人这是什么道理?(注:未执行时并非报错; 在SQL Server数据库下一切正常.)

[解决办法]
Access 中用 ? 而不是 @var
[解决办法]
将参数修改为?试试
string sql = "update wc_subject set sub_amount=sub_amount+1, sub_date=? where sub_id=?";
OleDbCommand command = new OleDbCommand(sql, connection);
command.Parameters.AddWithValue("?", DateTime.Now);
command.Parameters.AddWithValue("?", 1);
command.Connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();

热点排行