Last active
August 29, 2015 14:24
-
-
Save brazilnut2000/242ea3b0364256a24c47 to your computer and use it in GitHub Desktop.
Call SQL Server stored procedure using Dapper from C# console app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
public static SqlConnection GetOpenConnection() | |
{ | |
var dapperConnString = ConfigurationManager.ConnectionStrings["DapperConn"].ConnectionString; | |
var connection = new SqlConnection(dapperConnString); | |
connection.Open(); | |
return connection; | |
} | |
private static void GetBlogNamesFromDapper() | |
{ | |
var connection = GetOpenConnection(); | |
var blogNames = connection.Query<string>("GetMatchingBlogNames", new { likeMatch = "%15%" }, commandType: CommandType.StoredProcedure); | |
foreach (var blogName in blogNames) | |
{ | |
Console.WriteLine(blogName); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
GetBlogNamesFromDapper(); | |
Console.WriteLine("Press any key to exit..."); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment