SQL Data Types vs C# Data Types and Examples

If you want to program SQL queries in C# to insert or retrieve data from a table or a database, you may need to map SQL data types to C# data types. Here are the equivalents and examples for common SQL data types with C# data types:
MSSQL Data Types C# Data Types Description
bit bool Used for logical values. Can take values 0 or 1.
tinyint byte Represents integer values between 0 and 255.
smallint short Represents small integers (-32,768 to 32,767).
int int Represents integer values (-2,147,483,648 to 2,147,483,647).
bigint long Represents large integers (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
float float Represents floating-point numbers (7-digit precision).
real float Small precision floating-point type (4-digit precision).
decimal(p, s) decimal(p, s) or double Represents precise numbers. p specifies the total number of digits, and s specifies the number of decimal places.
numeric(p, s) decimal(p, s) Same as decimal, representing numeric data.
money decimal Represents currency values.
smallmoney decimal Represents smaller currency values.
char(n) string Represents fixed-length character strings.
varchar(n) string Represents variable-length character strings.
text string Represents long text values.
nchar(n) string Represents Unicode fixed-length character strings.
nvarchar(n) string Represents Unicode variable-length character strings.
ntext string Represents Unicode long text values.
datetime DateTime Represents date and time values.
smalldatetime DateTime Represents a smaller date and time value.
date DateTime Represents date values only.
time TimeSpan Represents a duration with hours, minutes, seconds, and milliseconds.
datetime2 DateTime Represents extended date and time values.
datetimeoffset DateTimeOffset Represents extended date, time, and time zone information.
binary(n) byte[] Represents fixed-length binary data.
varbinary(n) byte[] Represents variable-length binary data.
image byte[] Represents large binary data.