Recommended C# Data Type for SQL Server Image Data Type - C#

, , ,

According to a Microsoft document in managing ntext, text, and image Data, avoid using this feature in new development work. Use varchar(max), nvarchar(max), and varbinary(max) data types instead

byte[] is the recommended C# data type equivalent to image data type of SQL Server.

For example, the below SQL statement shows ProductImages table with an Image type column

CREATE TABLE [ProductImages]
(
[ProductImageID] [int] IDENTITY(1,1) NOT NULL,
[ProductImage] [image] NOT NULL
 CONSTRAINT [PK_ProductImages] PRIMARY KEY CLUSTERED
 (
   [ProductImageID] ASC
 ) 
)

This can be defined in a ProductImages C# class. Note that the SQL Server Image type is mapped with C# byte[] type

public class ProductImages
{
    private int productImageID;

    public int ProductImageID
    {
        get { return productImageID; }
        set { productImageID = value; }
    }

    private byte[] productImage;

    public byte[] ProductImage
    {
        get { return productImage; }
        set { productImage = value; }
    }

}