MS Access 2007查询与参数 [英] MS access 2007 query with param

查看:78
本文介绍了MS Access 2007查询与参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用此代码选择一些行.
当我使用

Hi

I am trying to selct some rows using this code.
When i use

cmd.CommandType = CommandType.TableDirect ;


错误即将到来,参数太少.当我使用


error coming is too few parameters. and when i use

cmd.CommandType = CommandType.StoredProcedure ;

时,错误是

error is

Unspecified error
Invalid operation

我在Windows上使用VS 2010和MS Office 2007
7个平台.

I am using VS 2010 and ms office 2007 on windows
7 platform.

try
            {
                OleDbCommand cmd = new OleDbCommand("byjobtitle", cnn);
                cmd.CommandType = CommandType.TableDirect ;
                OleDbParameter prm = new OleDbParameter("@jobtitle", OleDbType.VarChar, 20);
                prm.Direction = ParameterDirection.Input;
                prm.Value = "Owner";
                cmd.Parameters.Add(prm);
                DataSet ds = new DataSet();
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(ds);
                return ds.Tables[0];
            }
            catch (Exception ex)
            { return null; }
            finally { cnn.Close(); }


在使用VS 2008和XP之前,我已经完成了此操作,但没有收到任何错误提示.已经浪费了我的一天.请帮忙.


I have done this before on using VS 2008 ans XP i didnt get any suxh errors. wasted my one day already. Please help.

推荐答案

从您的参数名称中删除arobase"@"并使用存储过程commandType

例如:
Remove arobase "@" from your parameter name and use a stored procedure commandType

ex :
OleDbParameter prm = new OleDbParameter("jobtitle", OleDbType.VarChar, 20);
cmd.CommandType = CommandType.StoredProcedure ;


Office 2007不支持数据集填充接受参数的已保存查询. Office 2003的相同代码可以正常工作.

Excecutenonquery可以在Office 2007上与param配合使用.
Office 2007 doesnt support dataset to be filled with saved query which accepts parameter. The same code for office 2003 is working fine.

Excecutenonquery works fine with param on office 2007.


这篇关于MS Access 2007查询与参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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