ZZZ Code AI
Report Issues
Suggest Features
Blog/Newsletter
Login
Dapper Tools
Chat
Code Explain
Seed Data Generator
Sql Generator
Stored Procedure Generator
Entity to Table Converter
Table to Entity Converter
Sql Injection Detector
More Tools
When using a stored procedure, do I need to add 'EXEC' to the command text in Dapper?
<p>You don't need to add <code>EXEC</code> to the command text when specifing the command type to <code>CommandType.StoredProcedure</code>. However, you need add <code>EXEC</code> if you don't specify a command type or you set the command type to <code>CommandType.Text</code>.</p> <ol> <li>With <code>CommandType.StoredProcedure</code>, you don't have to use EXEC:</li> </ol> <pre><code class="language-csharp">using (var connection = new SqlConnection("connectionString")) { var result = connection.Query("MyStoredProcedure", commandType: CommandType.StoredProcedure).ToList(); } </code></pre> <ol start="2"> <li>With <code>CommandType.Text</code>, you must use EXEC:</li> </ol> <pre><code class="language-csharp">using (var connection = new SqlConnection("connectionString")) { var result = connection.Query("EXEC MyStoredProcedure", commandType: CommandType.Text).ToList(); } </code></pre> <ol start="3"> <li>With no command type specified, you must use EXEC:</li> </ol> <pre><code>using (var connection = new SqlConnection("connectionString")) { var result = connection.Query("EXEC MyStoredProcedure").ToList(); } </code></pre>
Sponsored by
Dapper Plus
This field is required
A text with a minimum of 10 characters is required
Send
Legal & Licensing
Answer generated by AI may produce inaccurate information about code, people, facts, and more.
Advertising Break!
5
seconds left
Did you know...
That you can now sponsor this project on
GitHub
?