问题
I have read a number of posts about this topic but still can't quite get it to work with my code.
Not sure if postgreSQL changes things...
Here is what I have that is (probably obviosly) not working:
string mySelectQuery = @"select distribution_stop_information.unique_id_no as stop_unique_id_no,
distribution_line_items.unique_id_no as line_unique_id_no, stop_name, stop_address,route_code AS RouteCode, customer_reference,
distribution_line_items.datetime_created, rma_number from distribution_stop_information join distribution_line_items on
distribution_line_items.unique_id_no = distribution_stop_information.unique_id_no
where distribution_line_items.datetime_created > '2/22/2017' and customer_no = :CustNo";
var dbCommand = db.CreateCommand();
var para = dbCommand.CreateParameter();
para.ParameterName = "CustNo";
para.Value = 91000;
//what do I put HERE to have it pass a parameter to replace the :CustNo???
var allStops = (List<stopsData>)db.Query<stopsData>(mySelectQuery,para);
The above generates the error: Parameter 'CustNo' is missing.
For now this is what I am doing until I get a better solution:
string stops_query = $@"select distribution_stop_information.unique_id_no as stop_unique_id_no,
distribution_line_items.unique_id_no as line_unique_id_no,
stop_name, stop_address,
rma_original_unique_id,
route_code,
customer_reference,
distribution_line_items.datetime_created as DateTimeCreated_LI,
rma_number from distribution_stop_information
join distribution_line_items on distribution_line_items.unique_id_no = distribution_stop_information.unique_id_no
where distribution_line_items.datetime_created > '{dateToCheck}' and customer_no = {TNGCustNo}";
来源:https://stackoverflow.com/questions/42440187/using-parameters-with-dapper