Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 739
techknackblogs Avatar asked Mar 25 '26 00:03

techknackblogs


1 Answers

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.

like image 97
Gord Thompson Avatar answered Mar 26 '26 14:03

Gord Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!