执行SQL查询时出现错误 [英] getting an error in executing the sql query

查看:97
本文介绍了执行SQL查询时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我收到类似

hi

i am getting an error like

<br />
<br />
Data type mismatch in criteria expression.<br />
<br />


的错误 我正在使用wpf(C#.net中的Windows应用程序)
iam使用access2003作为数据库
我尝试过如下


i am using wpf (windows application in C#.net )
iam using the access2003 as the database
i had tried as below

OleDbConnection mcon = new OleDbConnection("provider =Microsoft.JET.OLEDB.4.0;data source=D:\\invoice\\invoice.mdb");
               OleDbCommand da = new OleDbCommand("select companyname,customername from invoicetable where date BETWEEN ''&11/11/1975&'' AND ''&11/11/2004&''  order by ID desc", mcon);
               OleDbDataReader dr;
               mcon.Open();
               dr = da.ExecuteReader();


而且我也以这种方式迷恋了


and also i had trind in this way also

OleDbCommand da = new OleDbCommand("select companyname,customername from invoicetable where date BETWEEN ''11/11/1975'' AND ''11/11/2004''  order by ID desc", mcon);



在Access数据库中保存日期格式,例如"mm/dd/yyyy"的缩写形式
我正在做什么错误,请帮助我

感谢您的关注非常感谢



in access database in am saving in date formate like ''mm/dd/yyyy'' in shortformate
what is the error that i am doing, please help me

thankq for ur attention thank''s a lot

推荐答案

对于访问,请使用#表示日期.将日期转换为yyyy-mm-dd格式会更好.像
For access use # to represent date. Converting date into yyyy-mm-dd format would be better. Like
select companyname,customername from invoicetable where date BETWEEN #1975-11-11# AND #2004-11-11#  order by ID desc 


访问对日期有特定的表示法,我相信您必须将日期放在#"之间(因此#11/11/1975#).

但是,为此使用参数要好得多,这样可以保护自己免受SQL注入的侵害(如果您不知道它是什么,请使用Google注入).

在这种情况下,您将必须使用oledbparameter.
在SQL字符串中,将日期替换为?",然后按正确的顺序将参数添加到命令中.
Access has a specific notation for date''s, I believe you have to put your date between ''#'' (so #11/11/1975#).

But it would be far better to use parameters for this, you''ll protect yourself from SQL-injections (Google it if you don''t know what it is).

In this case you''ll have to use oledbparameter.
In your SQL string you replace the date''s with ''?'', and then you add your parameters in the correct order to your command.


这篇关于执行SQL查询时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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