Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing query parameters in Dapper using OleDb

Tags:

dapper

oledb

This query produces an error No value given for one or more required parameters:

using (var conn = new OleDbConnection("Provider=..."))
{
  conn.Open();
  var result = conn.Query(
    "select code, name from mytable where id = ? order by name",
    new { id = 1 });
}

If I change the query string to: ... where id = @id ..., I will get an error: Must declare the scalar variable "@id".

How do I construct the query string and how do I pass the parameter?

like image 808
Endy Tjahjono Avatar asked Sep 17 '13 10:09

Endy Tjahjono


1 Answers

The following should work:

var result = conn.Query(
"select code, name from mytable where id = ?id? order by name",
new { id = 1 });
like image 176
Marc Gravell Avatar answered Sep 18 '22 13:09

Marc Gravell