日期:2014-05-20  浏览次数:20779 次

用Access做数据库问题这么多,请哪位大哥帮我看一下!
private   void   SetInsertCommand(OleDbCommand   insert,TaskInfo   task)
{

string   cmd   =   "insert   into   tasks   "
+ "(taskNo,contractNo,taskName,taskDescription,planCompleteDate,completeDate, "
+ "planHours,hours,updateDate,updateUser,remark,charge) "
+ "values "
+ "(@taskNo,@contractNo,@taskName,@taskDescription,@planCompleteDate,@completeDate, "
+ "@planHours,@hours,@updateDate,@updateUser,@remark,@charge) ";

insert.CommandText   =   cmd;
insert.Connection   =   conn;

OleDbParameterCollection   OleDbParams   =   insert.Parameters;

/*1*/ OleDbParams.Add(new   OleDbParameter(TASKNO_PARM,OleDbType.VarChar));
/*2*/ OleDbParams.Add(new   OleDbParameter(CONTRACTNO_PARM,OleDbType.VarChar));
/*3*/ OleDbParams.Add(new   OleDbParameter(TASKNAME_PARM,OleDbType.VarChar));
/*4*/ OleDbParams.Add(new   OleDbParameter(TASKDESCRIPTION_PARM,OleDbType.VarChar));
/*5*/ OleDbParams.Add(new   OleDbParameter(PLANCOMPLETEDATE_PARM,OleDbType.Date));
OleDbParams.Add(new   OleDbParameter(COMPLETEDATE_PARM,OleDbType.Date));
OleDbParams.Add(new   OleDbParameter(PLANHOURS_PARM,OleDbType.Integer));
OleDbParams.Add(new   OleDbParameter(HOURS_PARM,OleDbType.Integer));
OleDbParams.Add(new   OleDbParameter(REMARK_PARM,OleDbType.VarChar));
OleDbParams.Add(new   OleDbParameter(UPDATEDATE_PARM,OleDbType.Date));
OleDbParams.Add(new   OleDbParameter(UPDATEUSER_PARM,OleDbType.VarChar));
OleDbParams.Add(new   OleDbParameter(CHARGE_PARM,OleDbType.VarChar));

//
//   Define   the   parameter   mappings   from   the   data   table   in   the
//   dataset.
//

OleDbParams[TASKNO_PARM].Value   =   task.getTaskNo();
OleDbParams[CONTRACTNO_PARM].Value   =   task.getContractNo();
OleDbParams[TASKNAME_PARM].Value   =   task.getTaskName();
OleDbParams[TASKDESCRIPTION_PARM].Value   =   task.getTaskDescription();
OleDbParams[PLANCOMPLETEDATE_PARM].Value   =   task.getPlanCompleteDate();
OleDbParams[COMPLETEDATE_PARM].Value   =   task.getCompleteDate();
OleDbParams[PLANHOURS_PARM].Value   =   task.getPlanHours();
OleDbParams[HOURS_PARM].Value   =   task.getHours();
OleDbParams[REMARK_PARM].Value   =   task.getRemark();
OleDbParams[UPDATEDATE_PARM].Value   =   task.getUpdateDate();
OleDbParams[UPDATEUSER_PARM].Value   =   task.getUpdateUser();
OleDbParams[CHARGE_PARM].Value   =   task.getCharge();
}
执行sql语句的时候,总是catch到一个异常!

标准表达式中数据类型不匹配

我检查了Access中的数据库,是3个日期时间类型,2个数字类型,其余的全是文本!没有错误啊!我郁闷了,哪里有错误啊?麻烦那位大哥告诉下!我一定高分相谢!!

------解决方案--------------------


重点看看有没有可能TaskInfo中的方法返回null的情况
另外:Access里面的日期格式要与DateTime格式化后的日期格式一致
------解决方案--------------------
循序要和sql一样