aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Multiple Results from Stored Procedure using Dapper in C#, VB.NET

Feb 18, 2015

Here I will explain how to get multiple results or records from stored procedure using dapper in
c#, or access multiple results or objects from stored procedure in dapper using querymultiple method in c#,

In previous articles I explained
start or stop IIS service in c#,, get values from ienumerable list in c#,, jQuery upload images without postback in, wcf tutorial for beginners with example in and many articles relating to AngularJS, jQuery,, c# and Now I will explain how to get multiple results or records from stored procedure using dapper in c#,

To get multiple results from stored procedure using dapper we need to use querymultiple method that would be like as shown

C# Code

using (IDbConnection conn = new SqlConnection(connectionString))
IEnumerable<dynamic> results = conn.Query(sql: storedProcedureName,param: parameters,commandType: CommandType.StoredProcedure);
var reader = conn.QueryMultiple(storedProcedureName, parameters, commandType: CommandType.StoredProcedure);
var userdetails = reader.Read<userdetails>().ToList();
var salarydetails = reader.Read<salraydetails>().ToList();

public class userdetails
public int userid;
public string username;
public class salraydetails
public int salary;
public int empid;


Using conn As IDbConnection = New SqlConnection(connectionString)
Dim results As IEnumerable(Of Dynamic) = conn.Query(sql:=storedProcedureName, param:=parameters, commandType:=CommandType.StoredProcedure)
Dim reader = conn.QueryMultiple(storedProcedureName, parameters, commandType:=CommandType.StoredProcedure)
Dim userdetails = reader.Read(Of userdetails)().ToList()
Dim salarydetails = reader.Read(Of salraydetails)().ToList()
End Using

Public Class userdetails
Public userid As Integer
Public username As String
End Class
Public Class salraydetails
Public salary As Integer
Public empid As Integer
End Class

I hope it helps you to get multiple results from stored procedure using dapper…….Happy Coding….

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Unknown said...

This post is not as like your previous post
First time i did not understand any thing
Please describe in detail with db connectivity and all
And please post its output ,too
Thank you

Unknown said...
This comment has been removed by the author.
Suresh Dasari said...

if you know about dapper ORM then you will understand this post....

SriRam said...

Hi suresh..

I have a question on it. In my scenario, i am getting about 5 result sets..If any of the result set returns null values.. then it throws an error. Please suggest me to proceed. Thanks in advance.

Chief said...


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.