Dapper for insert into Tables using Stored Procedure in Dotnet core
using Dapper;
using System;
using System.Data.SqlClient;
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Program
{
private static string connectionString = "YourConnectionStringHere";
public static void Main()
{
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
var user = new User
{
Name = "John Doe"
};
var sql = "InsertUser"; // Stored Procedure Name
var parameters = new { Name = user.Name };
var userId = connection.Query<int>(sql, parameters, commandType: System.Data.CommandType.StoredProcedure).Single();
Console.WriteLine($"Inserted user with ID: {userId}");
}
}
}
Comments
Post a Comment