Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parameterization of a query
Message
 
À
12/09/2010 15:49:19
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
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:
01480891
Vues:
72
This message has been marked as the solution to the initial question of the thread.
Not sure at all, but what if:
loODBCDataParameter = New OdbcParameter()
loODBCDataParameter.ParameterName = "@Last_Date" -- put the @ ate the beginning of the parameter name?
And BTW why I think you should have a question mark somewhere where the parameters should be placed?
"Select Last_Date From RO Where Last_Date > ?"
(again not sure :-))))))))))))



>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?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform