Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parameterization of a query
Message
De
12/09/2010 15:49:19
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Parameterization of a query
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01480890
Message ID:
01480890
Vues:
152
The following example is a demo code to query a SQL Anywhere database. I have been told that the parameterization for SQL Anywhere is the same as SQL Server, thus by the use of @. When I use that approach in ISQL, it works. But, when I do it from code, such as the following, it would generates the error:

"ERROR [42S22] [Sybase][ODBC Driver][SQL Anywhere]Column '@Last_Date' not found"
                Dim loCommand As IDbCommand = Nothing
                Dim loConnection As IDbConnection = Nothing
                Dim loDataAdapter As IDbDataAdapter = Nothing
                Dim loDataParameter As IDbDataParameter = Nothing
                Dim loDataSet As DataSet = New DataSet
                Dim loODBCDataParameter As OdbcParameter = Nothing

                ' Create the ODBC connection
                loConnection = New OdbcConnection("...")

                ' Open the connection
                loConnection.Open()

                ' Command
                loCommand = New OdbcCommand
                loCommand.Connection = loConnection
                loCommand.CommandText = "Select Last_Date From RO Where Last_Date>@Last_Date"

                ' ODBC parameter
                loODBCDataParameter = New OdbcParameter()
                loODBCDataParameter.ParameterName = "Last_Date"
                loODBCDataParameter.Value = Date.Now
                loODBCDataParameter.DbType = DbType.Date

                ' Add the parameter
                loCommand.Parameters.Add(loODBCDataParameter)

                ' Data adapter
                loDataAdapter = New OdbcDataAdapter()
                loDataAdapter.SelectCommand = loCommand
                loDataAdapter.Fill(loDataSet)
If I remove the Where clause, it works. Just to be sure that it works as is, the following works from ISQL:
Select Last_Date From RO Where Last_Date>'2010-05-11'
So, basically, as soon as I try to parameterize from code, it will always say that whatever is on the other side of the > character is not found.

But, from ISQL, if I parameterize as in SQL Server, such as:
Declare @Last_Date Date

Set @Last_Date='2010-05-11'

Select Last_Date From RO Where Last_Date>@Last_Date
It will work.

So, obviously, from the .NET environment, something is not compliant with SQL Anywhere. Is it because I use the ODBC driver?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform