?
Solved

OLEDB command parameters not being assigned in order in SQL string

Posted on 2006-07-01
4
Medium Priority
?
229 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

765 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