日期:2014-05-18  浏览次数:20731 次

Ado.net为何更新失败,求教!
程序大概如下:
OleDbConnection conn=new OleDbConnection(......;
OleDbCommand comm=new....................
comm.CommandText="update cangku set cangkuming=@cangkuming where id=@cangkuid";

comm.Parameters.Add(new OleDbParameter("cangkuid",3));
comm.Parameters.Add(new OleDbParameter("cangkuming","大陆"));

comm.ExecuteNonQuery();为何总是更新不成功,返回0!!!!!!!!!!!!求教

............说明:cangku是access中的表,有2个列:id,cangkuming



------解决方案--------------------
OLEDB数据库 参数用?代替
------解决方案--------------------
至少得写成
comm.Parameters.Add(new OleDbParameter("@cangkuid",3));
comm.Parameters.Add(new OleDbParameter("@cangkuming","大陆"));

这种,参数名前要加@。

当然用?占位符是最标准的写法,不过OleDb一定程度上也兼容@参数名
------解决方案--------------------
有出错信息吗,如果讲Parameters的值,直接放到sql中,执行有问题吗,或者放到数据库中执行看看有问题吗
------解决方案--------------------
comm.CommandText="update cangku set cangkuming=? where id=?";