Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OLEDB command parameters not being assigned in order in SQL string

Posted on 2006-07-01
4
Medium Priority
?
233 Views
Last Modified: 2011-04-14
The parameters for this OLEDB command are not being placed in the order in which they appear in the SQL string, probably due to nesting.  How can I determine the order in which they are being applied?

        strSql = "SELECT Subjects.SubjectID, Subjects.BusinessName, Subjects.City, Subjects.StateCode FROM (Subjects) WHERE (((Subjects.Zip) In (SELECT Zip FROM ZipCodes WHERE ? > 3959 * ATN( SQR(1 - (SIN(?/ 57.3) * SIN(LAT/ 57.3) + COS(?/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - (?/ 57.3))) ^2 ) / (SIN(?/ 57.3) * SIN(LAT/ 57.3) + COS(?/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - (?/ 57.3))) ) )))"
        objCmd = New OleDbCommand(strSql, objConn)
        setParam(objCmd, "Rad", OleDbType.Numeric, vRad)
        setParam(objCmd, "Lat", OleDbType.Numeric, vLat)
        setParam(objCmd, "Lat", OleDbType.Numeric, vLat)
        setParam(objCmd, "Lng", OleDbType.Numeric, vLng)
        setParam(objCmd, "Lat", OleDbType.Numeric, vLat)
        setParam(objCmd, "Lat", OleDbType.Numeric, vLat)
        setParam(objCmd, "Lng", OleDbType.Numeric, vLng)

    Protected Sub setParam(ByRef objCmd As OleDbCommand, ByVal strParamName As String, ByVal varType As OleDbType, ByVal varValue As Object)
        objCmd.Parameters.Add(strParamName, varType).Value = varValue
    End Sub

I know they aren't being applied in the correct order because when I take the variables as supplied to the command in the web application:
vRad = 50
vLat = 40.2411
vLng = 76.0567

and then apply them explicitly in a SQL statement to the Access database:
SELECT Subjects.BusinessName, Subjects.City, Subjects.StateCode
FROM Subjects
WHERE (((Subjects.Zip) In (SELECT Zip FROM ZipCodes WHERE 50 > 3959 * ATN( SQR(1 - (SIN(40.2411/ 57.3) * SIN(LAT/ 57.3) + COS(40.2411/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - (76.0567/ 57.3))) ^2 ) / (SIN(40.2411/ 57.3) * SIN(LAT/ 57.3) + COS(40.2411/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - (76.0567/ 57.3))) ) )));

I get 156 results, not the 5000+ returned by the OLEDB command.

I'm thinking there might be a way to surround one parameter at a time in the SQL string with some kind of internal function which will cause certain values to fail, and then supply test values one at a time to the command to determine the location of each ordered parameter, but I've already spent too much time on trial-and-error and think this is a job for.. the Experts Exchange!
0
Comment
Question by:psk1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 2000 total points
ID: 17024373
Access should let you force the parameter ordering by adding a parameter clause to your sql and then using the named parameters in your sql:

   strSql = "PARAMETERS myrad Long, mylat IEEEDouble, mylon IEEEDouble; SELECT Subjects.SubjectID, Subjects.BusinessName, Subjects.City, Subjects.StateCode FROM (Subjects) WHERE (((Subjects.Zip) In (SELECT Zip FROM ZipCodes WHERE [myrad] > 3959 * ATN( SQR(1 - (SIN([mylat]/ 57.3) * SIN(LAT/ 57.3) + COS([mylat]/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - ([mylon]/ 57.3))) ^2 ) / (SIN([mylon]/ 57.3) * SIN(LAT/ 57.3) + COS([mylat]/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - ([mylon]/ 57.3))) ) )))"

You'll still have to add them in the order you've defined them in your parameter clause:

  setParam(objCmd,"rad", OleDbType.Int32, vRad)
  setParam(objCmd,"lon", OleDBType.Double, vLon)
  setParam(objCmd,"lat", OleDBType.Double, vLat)

Give it a try.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17024379
Sorry... I can't even manage to keep them in the same order.  Time to pack it in:

  setParam(objCmd,"rad", OleDbType.Int32, vRad)
  setParam(objCmd,"lat", OleDBType.Double, vLat)
  setParam(objCmd,"lon", OleDBType.Double, vLon)
0
 
LVL 2

Author Comment

by:psk1
ID: 17025236
You did it.  Thanks (again) clockwatcher.
0
 
LVL 2

Author Comment

by:psk1
ID: 17025241
Seriously, thanks.  You've saved me much time and confusion and helped to keep the ball rolling.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question