Passing a DateTime value as a parameter to an OleDbCommand

元气小坏坏 提交于 2019-12-06 10:01:01

Make sure your data type for SomeDateField is DateTime and not Date. Also, try to make

p.DbType = DbType.DateTime;

When you'd use OleDbType.DateTime instead of DbType.Date, I'm sure it will work.

But, as I understand from your post, you do not want to be so specific, and use the more general DbType enum (and classes) ?

However, I think you should use the more specific OleDb classes in your data-access layer. Using the less specified 'DbType' classes, is kind of useless, because, when you're targetting another database-type, chances are quite big that your SQL-syntax will have to change as well, since each DBMS uses its own dialect (sometimes only minor changes, but still ... ).

OleDbType does not have a DateTime enumeraton http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbtype.aspx

If you use DBType.DateTime, "The type of a parameter is specific to the .NET Framework data provider. Specifying the type converts the value of the Parameter to the data provider Type before passing the value to the data source. If the type is not specified, ADO.NET infers the data provider Type of the Parameter from the Value property of the Parameter object. " http://msdn.microsoft.com/en-us/library/system.data.dbtype.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!