简体   繁体   中英

Dapper with MS Access Update and Insert issue

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM