How To

How to Update appsettings.json in C#
By Tan Lee Published on Mar 06, 2025 404

To update values programmatically within a settings JSON file, you will need to overwrite the entire settings.json file.

Injecting ILogger into Dapper Polly Retry Policy in C#
By Tan Lee Published on Mar 11, 2025 224

To inject ILogger into a Dapper Polly Retry Policy in C#, you can follow these steps.

Properly Disposing HttpContent When Using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 165

In versions prior to .NET Core 3.0 (including .NET Framework), database connection pooling was automatically managed by the framework, with the connection object being disposed of at the end of each operation.

How to send a file with HttpClient in C#
By Tan Lee Published on Mar 11, 2025 326

When uploading a file with HttpClient, you need to place the file inside a MultipartFormDataContent object, which will be sent as the body of the HTTP request.

How to Deserialize JSON with quoted numbers in C#
By Tan Lee Published on Mar 11, 2025 226

In JSON, numbers can be represented in two main formats: as literal numbers (e.g., 123) or as quoted strings (e.g., "123").

How to Configure HttpClient connection keep-alive in C#
By Tan Lee Published on Mar 11, 2025 376

When using a single instance of SqlConnection to interact with a database, the connection is pooled, meaning it can be reused for subsequent requests to improve performance.

Performance Benefits of Reusing Connections with HttpClient
By Tan Lee Published on Mar 11, 2025 128

To demonstrate the performance gains of keeping a database connection open and reusing it across multiple queries, I’ll perform multiple database queries to the same database.

How to add request headers when using HttpClient in C#
By Tan Lee Published on Mar 11, 2025 318

When using HttpClient to send requests in C#, there are two primary ways to add headers:

How to Delete records with Dapper in C#
By Tan Lee Published on Mar 10, 2025 216

In C#, you can use Dapper to delete records from a database by executing a DELETE statement with the Execute() method, passing in the record identifier as a parameter.

How to Execute a SELECT query with Dapper in C#
By Tan Lee Published on Mar 10, 2025 271

You can query a database in C# using Dapper by executing a SELECT query with the Query() method, specifying the type to map the results to, and optionally adding parameters.

How to Get inserted identity value with Dapper in C#
By Tan Lee Published on Mar 10, 2025 291

When inserting a record into a table that has an identity column, the database automatically generates a value for that column. To retrieve the identity value after the insert, you can use the OUTPUT INSERTED.<identity column name> clause in your SQL query.

How to add class to tr using jQuery datatable
By Tan Lee Published on May 16, 2024 2.02K

To add a class name to a DataTable using jQuery, you can use the className option when initializing the DataTable or you can add classes dynamically after the table has been initialized.