在标准前pression数据类型不匹配|访问,OLEDB,C# [英] Data type mismatch in criteria expression | Access, OleDb, C#

查看:164
本文介绍了在标准前pression数据类型不匹配|访问,OLEDB,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读使用C#从MS Access /更新数据。
我的code是:

I read/update data from MS Access using C#. My code is:

public static void UpdateLastLogin(int userid, DateTime logintime) ///logintime = DateTime.Now
{
    string sql = @"UPDATE [Customers] SET [LastLogin]=?";
    OleDbParameter[] prms = new OleDbParameter[] { 
     new OleDbParameter("@LastLogin",logintime)
    };
    using (DAL dal = new DAL())
    {
        dal.UpdateRow(sql, false, prms);
    }
}

当涉及到日期,我遇到了麻烦。
这引发了标准前pression数据类型不匹配。错误。
(我删除WHERE子句保持它的简单)
我是suuposed附上[LastLogin] =?单引号问号,#标志..于事无补。
如何处理datetime对象Access和OLEDB提供任何线索将大大AP preciated。

When it comes to Dates, I having trouble. This throws a "Data type mismatch in criteria expression." error. (I removed WHERE clause for keeping it simpler) Am I suuposed to enclose [LastLogin]=? question mark with single quotes, # signs .. does not help. Any leads on how to handle DateTime objects with Access and OleDb provider will be greatly appreciated.

先谢谢了。

推荐答案

有一个已知问题的OleDb和日期。尝试做这样的:

There is a known issue with OleDb and dates. Try doing something like:

OleDbParameter p = parameter as OleDbParameter;
if (null == p)
  parameter.DbType = DbType.DateTime;
else
  p.OleDbType = OleDbType.Date;

或者使用明确的格式字符串:

Or use explicit format string:

value.ToString("yyyy-MM-dd hh:mm:ss")

这篇关于在标准前pression数据类型不匹配|访问,OLEDB,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆