如何以编程方式确定查询参数引用的字段名称? [英] How to programmatically determinae the field name referenced by query param?

查看:66
本文介绍了如何以编程方式确定查询参数引用的字段名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下示例可以进一步澄清问题,

选择fieldA,filedB,fieldC

The following example may further clarify the question,
Select fieldA, filedB, fieldC

来自tblX
其中fieldD = Forms!formName!controlName


我想知道的是如何确定或获取(FieldD)以上

SQL stmt,这是一个保存的查询。同时,让我强调,我正在谈论

关于查询参数,而不是标准,标准的一个例子是

如下:

选择fieldA,提交B来自tblY
From tblX Where fieldD = Forms!formName!controlName

What I''d like to know is how to determine or get (FieldD) for the above
SQL stmt, which is a saved query. Meantime, let me stress, I''m talking
about query param(s), not criteria, an example of criteria is as
follows:
Select fieldA, filedBFrom tblY



其中fieldC =''thisValue''


如何?


Tia


Don


Where fieldC = ''thisValue''

How?

Tia

Don

推荐答案

Access(JET)不会暴露这个给你,所以你需要编写代码来解析查询语句并确定哪些是关键字,这些是表格

名称,字段名称,表别名,字段别名,文字,然后是哪个
名称与上述任何一个都不匹配。


任何不能解析为其他名称的东西,Access视为

参数。


如果这是您自己的数据库,您可以简化您的工作(并提高查询的可靠性

)通过声明参数。在查询设计视图中,

在查询菜单上选择参数,然后输入如下内容:

Forms!formName!controlName Long

那么你只有你必须解析查询的第一个子句,如果PARAMETERS子句中有多个条目,你可以使用

Split()。


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" NickName" <哒**** @ rock.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Access (JET) does not expose this to you, so you will need to write code to
parse the query statement and determine which are keywords, which are table
names, fields names, table aliases, field aliases, literals, and then which
names do not match any of the above.

Anything that does not resolve to another name, Access treats as a
parameter.

If this is your own database, you could simplify your job (and improve the
reliability of the query) by declaring the parameters. In query design view,
choose Parameters on the Query menu, and enter something like:
Forms!formName!controlName Long
Then you only have to parse the first clause of the query, and you could use
Split() if there are multiple entries in the PARAMETERS clause.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"NickName" <da****@rock.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
以下示例可以进一步阐明问题,
选择fieldA,filedB,fieldC
The following example may further clarify the question,
Select fieldA, filedB, fieldC
来自tblX


其中fieldD = Forms!formName!controlName

我想知道的是如何确定或获取(FieldD)以上的
SQL stmt,这是一个保存的查询。同时,让我强调,我正在谈论关于查询参数,而不是标准,标准的一个例子如下:
选择fieldA,filedB


Where fieldD = Forms!formName!controlName

What I''d like to know is how to determine or get (FieldD) for the above
SQL stmt, which is a saved query. Meantime, let me stress, I''m talking
about query param(s), not criteria, an example of criteria is as
follows:
Select fieldA, filedB

来自tblY


where fieldC =''thisValue''

如何?

Tia


Where fieldC = ''thisValue''

How?

Tia

Don



" NickName" <哒**** @ rock.com>写在

新闻:11 ********************** @ o13g2000cwo.googlegr psps.com:
"NickName" <da****@rock.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
以下示例可能进一步澄清问题,
选择fieldA,filedB,fieldC
The following example may further clarify the question,
Select fieldA, filedB, fieldC
来自tblX


其中fieldD = Forms!formName!controlName

我想知道的是如何为上面的SQL stmt确定或获取(FieldD),这是一个保存的查询。同时,让我强调,
我说的是查询参数,而不是标准,
标准的例子如下:
选择fieldA,filedB


Where fieldD = Forms!formName!controlName

What I''d like to know is how to determine or get (FieldD) for the
above SQL stmt, which is a saved query. Meantime, let me stress,
I''m talking about query param(s), not criteria, an example of
criteria is as follows:
Select fieldA, filedB

来自tblY


where fieldC =''thisValue''

如何?


Where fieldC = ''thisValue''

How?




正如Allen所说建议,你必须解析SQL以找到

参数,然后找出它适用的内容。这实际上比它看起来要复杂得多,因为在SQL语句的SELECT和WHERE子句中可以使用一个参数

(它可能是

可在ORDER BY中使用,但不是出于任何有意义的目的,似乎

me)。


但这里是现实检查:我几乎没有使用参数查询

all。原因是,作为表单或replort记录源,他们提供的UI和

错误恢复不适用于除了

快速和肮脏的解决方案之外的任何东西,并且他们进入在代码中使用相同的方式使用相同的问题,因为在代码中构造动态SQL语句时,它们更多地分配值而不是




所以,我只是不使用它们。


现在,对这个*的认识可以*是某个服务器返回的那个

结束,定义参数得到的处理比

简单定义一个WHERE子句更有效。但这只是服务器后端发生的一个特定子集的b / b $ b(与Jet

后端相反),并且只有当你是在那个位置。


作为一般做法,那么,我建议不要使用

参数查询,因为它们不能令人满意而没有代码

提供用户界面,一旦你进入代码,它们会带来更多的工作。


-

David W. Fenton http://www.bway.net/~dfenton

dfenton在bway dot net http://www.bway.net/~dfassoc


好吧,艾伦在MS内部NG上对我的''查询'做出回应,所以,我不会在这里重复
除外再次感谢。


好​​的,关于Jet参数查询的不受欢迎程度后端数据库,我已经

想补充一点,这个特殊的Access 97数据库我已经掌握了很多表格(可能是他们可能是被视为Access UI),

,其中许多都调用参数查询。无论如何,我的目标是找到一些

有效的方法来识别和转换这些类型的查询到sql

服务器的存储过程,没有识别问题(其中

有param,但没有。)


虽然有这个属性,但是很有趣的是,Parameters.Count但不是

Parameters.Name。 MS Access如何获取Parameters.Count而不知道

每个名字,模拟,一个家庭知道它有5个孩子但不知道每个

孩子的名字?


Don L.

David W. Fenton写道:
Well, Allen has responded to my ''query'' on an MS internal NG, so, I
won''t repeat here except once again thanks.

OK, on the undesirability of parameter queries for Jet back end db, I''d
like to add that, this particular Access 97 db I have my teeth on has
quite a lot of forms (probably they could be considered as Access UI),
and many of them call parameter queries. Anyway, my goal is find some
efficient way to identify and convert these kind of queries to sql
server''s stored procedures, no problem with identification (of which
has param which does not).

It''s funny though there''s this property, Parameters.Count but not
Parameters.Name. How do MS Access get Parameters.Count without knowing
each name, analogue, a family knows it has 5 kids but don''t know each
kid''s name?

Don L.

David W. Fenton wrote:
" NickName" <哒**** @ rock.com>在
新闻中写道:11 ********************** @ o13g2000cwo.googlegr psps.com:
"NickName" <da****@rock.com> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
以下示例可以进一步阐明问题,
选择fieldA,filedB,fieldC
The following example may further clarify the question,
Select fieldA, filedB, fieldC
来自tblX


其中fieldD = Forms!formName!controlName

我想知道的是如何为上面的SQL stmt确定或获取(FieldD),这是一个保存的查询。同时,让我强调,
我说的是查询参数,而不是标准,
标准的例子如下:
选择fieldA,filedB


Where fieldD = Forms!formName!controlName

What I''d like to know is how to determine or get (FieldD) for the
above SQL stmt, which is a saved query. Meantime, let me stress,
I''m talking about query param(s), not criteria, an example of
criteria is as follows:
Select fieldA, filedB

来自tblY


where fieldC =''thisValue''

如何?


Where fieldC = ''thisValue''

How?



正如艾伦建议的那样,你有解析SQL以找到
参数,然后找出它适用的内容。这实际上比看起来要复杂得多,因为参数可以在SQL语句的SELECT和WHERE子句中使用
(它可能在ORDER BY中可用) ,但不是为了任何有意义的目的,似乎
我。

但这里是一个现实检查:我几乎没有使用参数查询
。原因是,作为表单或replort记录源,它们提供的UI和
错误恢复不适用于除了快速和脏的解决方案之外的任何东西,并且它们妨碍了使用相同的
代码中的QueryDefs,因为它们更多的工作来分配值而不仅仅是在代码中构造动态SQL语句。

所以,我只是不使用它们。

现在,对* *的认识可能是因为某些服务器返回结束,定义参数的处理比仅仅定义WHERE子句更有效。但这只是服务器后端发生的特定情况的一部分(与Jet
后端相反),并且仅在你处于该位置时才有保证。

作为一般惯例,我建议不要使用
参数查询,因为它们不能令人满意,没有代码来提供UI,并且一旦你进入代码就会导致更多的工作。

-
David W. Fenton http:/ /www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc






这篇关于如何以编程方式确定查询参数引用的字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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