Dapper for update Tables 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

            {

                Id = 1,

                Name = "Updated Name"

            };


            var sql = "UPDATE Users SET Name = @Name WHERE Id = @Id";


            var affectedRows = connection.Execute(sql, user);

            Console.WriteLine($"Number of rows updated: {affectedRows}");

        }

    }

}


Comments

Popular posts from this blog

Multiline to singleline IN C# - CODING

EF Core interview questions for beginners

EF Core interview questions for experienced