刚刚解决了这个问题-它是参数的命名-看来您无法在查询中为任何字段命名相同的参数。
将查询从以下位置更改:
UPDATE tableName SET tableName.LastPolledDtg = LastPolledDtgWHERe tableName.key = ID;
到:
UPDATE tableName SET tableName.LastPolledDtg = LastPolledDtgArgWHERe tableName.key = ID;
…并通过更改参数名称来更新调用C#,从而将其写入数据库。
但是,还有一点麻烦:
将参数顺序保留在C#中,将导致数据库中的LastPolledDtg字段以最小日期(1899左右)进行更新。重新排序参数到OleDbCommand的添加,以匹配它们在SQL中的出现,从而解决了此问题。
因此,C#应该如下所示:
OleDbCommand command = new OleDbCommand();SetCommandType(command, CommandType.StoredProcedure, "NameOfQueryInAccessDatabase");AddParamToSQLCmd(command, "@LastPolledDtgArg", OleDbType.Date, 4, ParameterDirection.Input, DateTime.Now);AddParamToSQLCmd(command, "@ID", OleDbType.Integer, 4, ParameterDirection.Input, id);using (OleDbConnection connection = new OleDbConnection("connectionString")){command.Connection = connection;connection.Open();result = command.ExecuteNonQuery();}男人,我喜欢Access。



