Dapper with MS Access Update and Insert issue

[亡魂溺海] 提交于 2019-12-10 20:58:37

问题


I am using Dapper to Update and Insert Access DB. Code is working not throwing exception but its not updating the value in DB. Below is my code

sql.Append("UPDATE drugs_repository SET drug_name = @DrugName ");

sql.Append(" WHERE id = @DrugId");

var parameters = new
{
    DrugName = objDrug.DrugName,                           
    DrugId = objDrug.DrugId
};
var t = connection.Query<string>(sql.ToString(), parameters);

Can someone please let me know what exactly I am missing in the above code? When I hardcode the value than its updating in the DB. So probably its related to parameter.


回答1:


If you are nervous about possible side-effects from removing the .OrderBy() in the Dapper code then a workaround would be to name your parameters in such a way that they will sort in the same order that they appear in the SQL command. For example, I suspect that the unmodified Dapper code would probably work okay if the parameters were named @1DrugName and @2DrugId.



来源:https://stackoverflow.com/questions/19479288/dapper-with-ms-access-update-and-insert-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!