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

请帮忙解决update语句异常

2012-02-10 
请帮忙解决update语句错误?我的是access数据库,检查了很多次,还是提示错误?请高手帮忙解决?提示:---------

请帮忙解决update语句错误?
我的是access数据库,检查了很多次,还是提示错误?请高手帮忙解决?
提示:---------------------------

---------------------------
UPDATE 语句的语法错误。
---------------------------
确定  
---------------------------
代码如下:
OleDbCommand UpdateCommand = new OleDbCommand();
  UpdateCommand.Connection = connection;
  string updatesql = "update from zhangdan set CustomerID=@CustomerID,DeviceName=@DeviceName,count=@count,UnitPrice=@UnitPrice,AllUnitPrice=@AllUnitPrice,DataTime=@DataTime where ID=@ID";
  UpdateCommand.CommandText = updatesql;

  UpdateCommand.Parameters.Add("@CustomerID", OleDbType.Integer, 4, "CustomerID");
  UpdateCommand.Parameters.Add("@DeviceName", OleDbType.VarChar, 20, "DeviceName");
  UpdateCommand.Parameters.Add("@count", OleDbType.Integer, 4, "count");
  UpdateCommand.Parameters.Add("@UnitPrice", OleDbType.VarChar, 20, "UnitPrice");
  UpdateCommand.Parameters.Add("@AllUnitPrice", OleDbType.VarChar, 20, "AllUnitPrice");
  UpdateCommand.Parameters.Add("@DataTime", OleDbType.DBTimeStamp, 20, "DataTime");
  UpdateCommand.Parameters.Add("@ID", OleDbType.Integer, 4, "ID");
  adapter.UpdateCommand = UpdateCommand;

[解决办法]
OleDbCommand UpdateCommand = new OleDbCommand();
UpdateCommand.Connection = connection;
string updatesql = "update from zhangdan set CustomerID=?,DeviceName=?,count=?,UnitPrice=?,AllUnitPrice=?,DataTime=? where ID=?";
UpdateCommand.CommandText = updatesql;

UpdateCommand.Parameters.Add("?", OleDbType.Integer, 4, "CustomerID");
UpdateCommand.Parameters.Add("?", OleDbType.VarChar, 20, "DeviceName");
UpdateCommand.Parameters.Add("?", OleDbType.Integer, 4, "count");
UpdateCommand.Parameters.Add("?", OleDbType.VarChar, 20, "UnitPrice");
UpdateCommand.Parameters.Add("?", OleDbType.VarChar, 20, "AllUnitPrice");
UpdateCommand.Parameters.Add("?", OleDbType.DBTimeStamp, 20, "DataTime");
UpdateCommand.Parameters.Add("?", OleDbType.Integer, 4, "ID");
adapter.UpdateCommand = UpdateCommand;
[解决办法]
都没有给各个变量赋值。

热点排行