Passing parameters to Dapper Select query for Oracle database

user7191279

I'm trying to pass parameters to Dapper for a select query in an Oracle database, but somehow, it doesn't work with the ":" identifier.

It works fine using string concatenation :
string req = "SELECT * FROM contact WHERE code_comite = '"; req += user.Comite + "' AND (pers_name LIKE '"; req += name + "%' OR pers_surname LIKE '" + name + "%')"; contacts = db_conn.Query<Contact>(req).ToList();

But not with Dapper parameters passing :

string comite = "'" + user.Comite + "'";//e.g. comite = '120'
name = "'" + name + "%'";//e.g. name = 'John%'
contacts = db_conn.Query<Contact>("SELECT * FROM contact WHERE code_comite = :code_comite AND (pers_nom LIKE :search OR pers_prenom LIKE :search)", new { code_comite = comite, search = name }).ToList();

It should use the same string but the second example returns me nothing.

Steve

You don't need to put quotes around your values when you pass a parameter. On the contrary this causes a fail because the engine will search a column containing your values surrounded by the literal quotes.
Just use the plain text

 string comite = user.Comite;
 name = name + "%";
 contacts = db_conn.Query<Contact>(@"SELECT * FROM contact 
          WHERE code_comite = :code_comite 
            AND (pers_nom LIKE :search 
                 OR pers_prenom LIKE :search)", 
  new { code_comite = comite, search = name }).ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing query parameters in Dapper using OleDb

From Dev

Passing Date to NamedParameterJdbcTemplate in Select query to oracle

From Dev

passing parameters from 2 select queries to another select query

From Dev

passing parameters from 2 select queries to another select query

From Dev

Collection parameters querying oracle with dapper

From Dev

Handle Oracle Database Connection in Dapper

From Dev

capybara not passing select parameters

From Dev

passing parameter to oracle query

From Dev

Passing Parameters to a SQLSRV WHERE IN query

From Dev

Passing in query parameters to a WCF Service

From Dev

Passing dynamically created SQL Parameters into dapper as an anonymous type

From Dev

Passing Output parameters to stored procedure using dapper in c# code

From Dev

SQL query for passing xml into database

From Dev

Oracle Database SQL Query

From Dev

Oracle Database Query Design

From Dev

Query limit in oracle database

From Dev

xml select query oracle

From Dev

Oracle Select Query optimization

From Dev

Oracle passing outer query value to inner query

From Dev

Joomla database query SELECT AS

From Dev

Filter query according to the parameters Oracle

From Dev

Passing conditional parameters to Database.SqlQuery

From Dev

Oracle select query with inner select query error

From Dev

Passing parameters to Ajax request in Select2

From Dev

query entity with linq passing in two parameters

From Dev

Mule Sql Query - passing parameters to the IN operator

From Dev

Passing list of enum values as HTTP query parameters

From Dev

Passing username and password in HTTP GET query parameters

From Dev

Mule Sql Query - passing parameters to the IN operator

Related Related

HotTag

Archive