Run stored Microsoft Access action query with Dapper

c# dapper ms-access

Question

As the title mentions, is there any way to run a stored Microsoft Access action query with Dapper? By action query I mean anything that doesn't return results (insert, update, delete).

I tried something like this but that would have been too easy I guess:

_connection.Execute("MyStoredQuery");

Accepted Answer

Dapper needs to know what is "MyStoredQuery". It doesn't scan the database schema to find out if that string is a normal sql command or the name of a stored procedure. (Well they are not really stored procedure but this is the meaning)

You need to specify the CommandType

_connection.Execute("MyStoredQuery", commandType = CommandType.StoredProcedure);

By default the CommandType is set to Text and this means that your string is expected to be a normal sql command text like SELECT...., INSERT INTO .... etc...

Not able to test it now, but let's see if someone with more knowledge about this could give you a better answer. (Hint add the Dapper tag to your question)


Popular Answer

Same answer as Steve except however "commandType=" did not work for me. I used "commandType:" as shown below:

_connection.Execute("MyStoredQuery", commandType: CommandType.StoredProcedure);


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