473,503 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a query call parametric

Hi all,
I'm trying to build a function that - providing the dbname and the query
name - show the results.

I don't know how to solve this problem...

when I try to insert the variable into this call

cnnSimple.x_qry rstSimple

where x_qry is the variable I get the error "Type mismatch: 'x_qry'"
obviously because the x_qry is a string...

I can't find how to cast the value in order to get the function work
correctly.
My target is to have a function like that: ShowTable(dbname,queryname)

Thanks
PGei
Jul 22 '05 #1
3 1977
PiGei wrote:
Hi all,
I'm trying to build a function that - providing the dbname and the
query name - show the results.

I don't know how to solve this problem...

when I try to insert the variable into this call

cnnSimple.x_qry rstSimple

where x_qry is the variable I get the error "Type mismatch: 'x_qry'"
obviously because the x_qry is a string...

I can't find how to cast the value in order to get the function work
correctly.
My target is to have a function like that: ShowTable(dbname,queryname)


This should answer your immediate question:
http://groups-beta.google.com/group/...d322b882a604bd

This will provide a little more information:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2
PiGei wrote:
Hi all,
I'm trying to build a function that - providing the dbname and the
query name - show the results.

I don't know how to solve this problem...

when I try to insert the variable into this call

cnnSimple.x_qry rstSimple

where x_qry is the variable I get the error "Type mismatch: 'x_qry'"
obviously because the x_qry is a string...

I can't find how to cast the value in order to get the function work
correctly.
My target is to have a function like that: ShowTable(dbname,queryname)

Oops, ignore the last message. I did not recognize that x_qry was a variable
containing the name of a saved query ...

In order to do what you want (specify the name of the query in the argument
to the function), you will need to either use dynamic sql, or a Command
object. My preference is the latter, due to security concerns.

Dynamic SQL approach:

const adCmdText = 1
sSQL = "Exec " & x_qry
Set rstSimple = cnnSimple.Execute(sSQL,,adCmdText)

Hopefully, if you are using this approach, you will validate that x_qry
contains a valid query name before executing it. This will mitigate the
dangers of sql injection and cross-site scripting, two techniques that
hackers can use to gain access to your system. You can use ADOX to get the
names of your views (non-parameterized saved queries) and procedures
(parameterized saved queries). You can store them in an array or xml
document (recommended) in Application (using appliction_onstart in
global.asa) so you don't have to query the database every time you want to
use this function to execute a saved query.
Command object approach:

const adCmdStoredProc = 4
Set cmd = createobject("adodb.command")
cmd.CommandText=x_qry
cmd.CommandType = adCmdStoredProc
Set cmd.ActiveConnection = cnnSimple
Set rstSimple = cmd.Execute

Advantage: no chance of sql injection using this approach. No need to do
extra processing to validate x_qry. Just catch the error that occurs if a
hacker attempts to pass a sql statement to this function.
More about the dynamic SQL approach:
http://www.aspfaq.com/show.asp?id=2201

And the reasons I dislike that approach:
http://tinyurl.com/jyy0

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #3
Thanks again for your help Bob
PGei

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
PiGei wrote:
Hi all,
I'm trying to build a function that - providing the dbname and the
query name - show the results.

I don't know how to solve this problem...

when I try to insert the variable into this call

cnnSimple.x_qry rstSimple

where x_qry is the variable I get the error "Type mismatch: 'x_qry'"
obviously because the x_qry is a string...

I can't find how to cast the value in order to get the function work
correctly.
My target is to have a function like that: ShowTable(dbname,queryname)

Oops, ignore the last message. I did not recognize that x_qry was a
variable containing the name of a saved query ...

In order to do what you want (specify the name of the query in the
argument to the function), you will need to either use dynamic sql, or a
Command object. My preference is the latter, due to security concerns.

Dynamic SQL approach:

const adCmdText = 1
sSQL = "Exec " & x_qry
Set rstSimple = cnnSimple.Execute(sSQL,,adCmdText)

Hopefully, if you are using this approach, you will validate that x_qry
contains a valid query name before executing it. This will mitigate the
dangers of sql injection and cross-site scripting, two techniques that
hackers can use to gain access to your system. You can use ADOX to get the
names of your views (non-parameterized saved queries) and procedures
(parameterized saved queries). You can store them in an array or xml
document (recommended) in Application (using appliction_onstart in
global.asa) so you don't have to query the database every time you want to
use this function to execute a saved query.
Command object approach:

const adCmdStoredProc = 4
Set cmd = createobject("adodb.command")
cmd.CommandText=x_qry
cmd.CommandType = adCmdStoredProc
Set cmd.ActiveConnection = cnnSimple
Set rstSimple = cmd.Execute

Advantage: no chance of sql injection using this approach. No need to do
extra processing to validate x_qry. Just catch the error that occurs if a
hacker attempts to pass a sql statement to this function.
More about the dynamic SQL approach:
http://www.aspfaq.com/show.asp?id=2201

And the reasons I dislike that approach:
http://tinyurl.com/jyy0

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5076
by: rednexgfx_k | last post by:
All, Problem Summary: I've running about 30 make table queries via VBA in Access 2000, and my database goes from 14,000k to over 2,000,000k. In addition, the longer the procedure runs, the...
4
4323
by: Gilberto Campos | last post by:
Hi all. I am having a strange problem. I am developping an application that acceses an Access db through Jet (.UDL files). I have writen parametric INSERT queries that work fine. I am now...
4
2107
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r)...
13
2826
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
6
5896
by: Ian Boyd | last post by:
Every time during development we had to make table changes, we use Control Center. Most of the time, Control Center fails. If you try to "undo all", it doesn't, and you end up losing your identity...
0
1322
by: sorin.lerner | last post by:
********************************************************************* * ACM SIGPLAN-SIGACT Symposium * * on ...
0
1029
by: jml1988 | last post by:
I am trying to open a parametric query in VB 6 from a Access 2000 file. I am trying a ADODC file using the SQL but am having problems, if anyone could help me it would be appricated. JML
0
1241
by: Dexter | last post by:
This new applet in MathEasy series allows computing length of an arc represented by parametric curve x(t) , y(t). It shows the resulting graph and the numerical answer for curve length Visit...
0
1389
by: tkip | last post by:
Gents.. I am just looking for ideas as to how to approach the query of DB I am working on. Basically, it's a database of welding procedures and depending on the metal you choose, appropriate...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.