Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile query with parameters for ODBC Connection #691

Open
mconca-kube opened this issue Sep 21, 2023 · 0 comments
Open

Compile query with parameters for ODBC Connection #691

mconca-kube opened this issue Sep 21, 2023 · 0 comments

Comments

@mconca-kube
Copy link

I noticed that Dapper requires a different syntax for parameters in query depending on which type of connection you use.
I'm using a SQL Server database.

This is the code that works for a SqlConnection (using parameters with a @ sign):

var connectionString = @"Data Source=localhost;Initial Catalog=ComunicazioniGulliver;User ID=sa;Password=kubeswap.01";
var connection = new SqlConnection(connectionString);
connection.Open();

         var parms = new DynamicParameters();
         parms.Add("p0", 0);
         parms.Add("p1", 20);

         var res2 = connection.Query(
	"SELECT [B04TDO0E].* FROM [dbo].[B04TDO0E] ORDER BY (SELECT 0) OFFSET @p0 ROWS FETCH NEXT @p1 ROWS ONLY",
             parms);

This is the query that works with an ODBC connection (using parameters surrounded by question marks).

var connectionString = "DSN=ComunicazioniSqlServer;UID=sa;PWD=kubeswap.01";
var connection = new System.Data.Odbc.OdbcConnection(connectionString);
connection.Open();

var parms = new DynamicParameters();
parms.Add("p0", 0);
parms.Add("p1", 20);

var res2 = connection.Query(
[B04TDO0E].* FROM [dbo].[B04TDO0E] ORDER BY (SELECT 0) OFFSET ?p0? ROWS FETCH NEXT ?p1? ROWS ONLY",
    parms);

SqlKata always compiles queries with the first syntax (@), but how should I manage odbc connections?
I would need a way to tell SqlKata to compile parameters using quotation marks.
I need to connect to this database using ODBC but my queries do not work this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant