How To

Invoke or BeginInvoke cannot be called on a control until the window handle has been created
By Tan Lee Published on Mar 20, 2025 90

In a WinForms project, if you try to call Invoke or BeginInvoke on a control before the window handle has been created, you'll encounter the following exception:

How to convert string into Secure string in C#
By Tan Lee Published on Jul 06, 2024 884

A SecureString in C# is designed to securely store confidential information such as passwords and PIN codes. It ensures that sensitive data is encrypted and remains protected in memory.

How to retrieve the Executable Path in C#
By Tan Lee Published on Jul 03, 2024 3.52K

In C#, you can retrieve the executable path of the current application using the System.Reflection namespace.

Connection string password with special characters in C#
By Tan Lee Published on Jun 21, 2024 2.49K

When you create a connection string in C# that includes a password with special characters, it's important to properly format and escape those characters to ensure the connection string is interpreted correctly.

Async/Await with a Func delegate in C#
By Tan Lee Published on Jan 21, 2025 438

To make a Func delegate awaitable, you need to return a Task from the delegate.

How to use a list of tuples in C#
By Tan Lee Published on Mar 05, 2025 373

In C#, a list of tuples can be used to store a collection of data where each element contains multiple values.

How to set time to 00:00:00 with GETDATE() in SQL
By Tan Lee Published on Oct 07, 2024 1.95K

In SQL Server, if you want to set the time part of the current date to 00:00:00 while using GETDATE(), you can use the CAST or CONVERT function to strip the time portion.

The name 'Session' does not exist in the current context
By Tan Lee Published on Jun 13, 2024 1.89K

In ASP.NET Core, the Session feature is not enabled by default and must be explicitly configured.

Implementing Two-Factor Authentication with Google Authenticator in ASP.NET Core
By Tan Lee Published on Mar 03, 2025 515

In this article, we'll explore how to implement two-factor authentication (2FA) in an ASP.NET Core web application using Time-Based One-Time Password (TOTP) apps, like Google Authenticator and Authy.

SQL Bulk Insert with SqlBulkCopy in C#
By Tan Lee Published on Mar 19, 2025 124

When dealing with a large number of records, especially in scenarios where inserting a lot of data into the database, a Bulk Insert can drastically improve performance over executing individual INSERT statements. Bulk Insertion can be up to 20x faster than inserting records one by one.

How to Use SqlDataReader to process multiple result sets in C#
By Tan Lee Published on Mar 19, 2025 154

In this article, I'll demonstrate how to use the SqlDataReader ADO.NET class in two scenarios involving multiple result sets:

How to use SqlBulkCopy in C#
By Tan Lee Published on Dec 13, 2024 574

SqlBulkCopy is a class in the System.Data.SqlClient namespace in C# that provides an efficient way to bulk load data into SQL Server databases.