Hi guys,
I am having trouble using Dapper. Getting must declare scalar variable @orderNo error.
How can I fix this?
private async Task GetDataForPdf(string orderNo)
{
var connString = _configuration["ConnectionStrings:Production"];
await using var sqlConnection = new SqlConnection(connString);
sqlConnection.Open();
await using var command = new SqlCommand { Connection = sqlConnection };
const string sql =
@"select od.quantity, od.productCode, od.productName, od.price, od.quantity * od.price As Total, o.orderTotalPrice, o.orderDate, o.orderBy,o.email
from Orders o
inner join OrderDetail od ON od.orderId = o.id
where od.status = 2 and o.orderNo = @orderNo";
command.Parameters.Add(new SqlParameter("orderNo", orderNo));
try
{
//Dapper
var results = await sqlConnection
.QueryAsync<PdfDto>(sql);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
//generate Pdf
//SendEmailWithColumns(results);
}
Thank you.