提出了oledb例外 [英] oledb exception was raised

查看:128
本文介绍了提出了oledb例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i在尝试执行以下查询时遇到问题。我在互联网上搜索异常,发现使用保留关键字可能会引发此问题,并且使用括号可能解决了这个问题。但是我在我的sql语句中一直使用括号,但仍然是IErrorInfo.GetDescription失败并且E_FAIL(0x80004005)。出现。

请给我一些帮助。

Hi guys,
i just faced a problem when trying to execute the following query.I searched for the exception on the internet and found that using a reserved keyword might raise this issue,and using brackets may solve this problem.But i use brackets all the time in my sql statements but still the exception 'IErrorInfo.GetDescription failed with E_FAIL(0x80004005).' comes up.
Please give me some hand.

qry2 = "SELECT * FROM [per_diem_accomodation] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "'" & _
        "AND [current month]= (SELECT MAX(current month) FROM [per_diem_accomodation] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "')"

推荐答案

您的查询中的间距略有偏差,请参阅下面的更改:

Your spacing in your query is slightly off, see the alteration below:
qry2 = "SELECT * FROM [per_diem_accomodation] WHERE [project number]='" & projcode & "' AND [employee number]='" & empcode & "'" & _

     " AND [current month]= (SELECT MAX(current month) FROM [per_diem_accomodation] WHERE 

[project number]='" & projcode & "' AND [employee number]='" & empcode & "')"





查询中的第二个AND有一个在它之前的空间。



The second "AND" in your query has a space before it.


Nebilo写道:



@Richard C Bishop我认为这不是间距问题,我已经尝试了但是它仍然不起作用


@Richard C Bishop I think it's not the spacing issue,i've tried it but still it doesn't work





好​​的,第二个错误在这里: MAX(当月),替换为: MAX([当前月份])



您使用过访问2007保留字和符号 [ ^ ]:'';)





但我建议你改变你试图实现这一目标的方式。正如Wes Aday所提到的,使用参数化查询:





OK, second error is here: MAX(current month), replace with: MAX([current month])

You had used one of Access 2007 reserved words and symbols[^]: 'month' ;)


But i'd suggest you to change the way you're trying to achieve that. As Wes Aday had mentioned, use parametrized queries:

PARAMETERS [projcode] CHAR, [empcode] CHAR; 
SELECT *
FROM [per_diem_accomodation]
WHERE [project number]= [projcode] AND [employee number]= [empcode] AND [current month]= 
    (SELECT MAX([current month])
     FROM [per_diem_accomodation]
     WHERE [project number]=[projcode AND [employee number]=[empcode]);







然后运行具有命名参数的OleDbCommand [ ^ ]。



更多关于: PARAMETERS声明(MS Access) [ ^ ]





[/ EDIT]




Then run OleDbCommand with named parameters[^].

More about: PARAMETERS declaration (MS Access)[^]


[/EDIT]


这篇关于提出了oledb例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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