Dapper with MS Access Update and Insert issue

c# dapper ms-access

Question

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.

Accepted Answer

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.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why