Open links in new tab
    • Set Up the Database Table Create a table in your database with a column to store the image as a binary data type (e.g., VARBINARY(MAX) or IMAGE if still supported). Example: CREATE TABLE Images ( Id INT PRIMARY KEY IDENTITY, ImageData VARBINARY(MAX), Description NVARCHAR(255) );

    • Add an Image Control to Your Web Form Use an <asp:Image> control to display the image and a <FileUpload> control to upload the image. Example: <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="UploadButton" runat="server" Text="Upload" OnClick="UploadButton_Click" /> <asp:Image ID="Image1" runat="server" />

    • Write the Code to Upload and Save the Image In the UploadButton_Click event, retrieve the uploaded file, convert it to a byte array, and save it to the database. Example: protected void UploadButton_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { // Convert uploaded file to byte array byte[] imageBytes; using (var memoryStream = new MemoryStream()) { FileUpload1.PostedFile.InputStream.CopyTo(memoryStream); imageBytes = memoryStream.ToArray(); } // Save the image to the database string connectionString = "YourConnectionStringHere"; using (SqlConnection conn = new SqlConnection(connectionString)) { string query = "INSERT INTO Images (ImageData, Description) VALUES (@ImageData, @Description)"; using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.AddWithValue("@ImageData", imageBytes); cmd.Parameters.AddWithValue("@Description", "Uploaded Image"); conn.Open(); cmd.ExecuteNonQuery(); } } // Display success message Image1.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(imageBytes); } else { // Handle case where no file is uploaded Response.Write("Please select an image to upload."); } }

  1. How to save Images to database using ASP.NET Core?

    It is not a good idea to save files to the database, your database may get huge quickly, which makes backing up and restoring problematic.

    • Reviews: 3

      Code sample

      byte[] p1 = null;
      using (var fs1 = Image.OpenReadStream())
      using (var ms1 = new MemoryStream()) {
        fs1.CopyTo(ms1);
        p1 = ms1.ToArray();...
    • Upload Image and Save in Database in ASP.Net MVC

      Dec 24, 2025 · In this article I will explain with an example, how to upload Image and save in Database in ASP.Net MVC Razor. The Images will be uploaded and converted to Binary format (Byte Array) and …

    • file upload - How to save Images to database using ASP.NET Core?

      This guide provides a foundational approach to saving images to a database in an ASP.NET Core application. Adjustments may be necessary based on your specific requirements and environment.

    • How to Upload and Save Images Into Database Using …

      In this article we will learn how to upload and save images into the database using ASP.NET.

    • saving png image to the database - Microsoft Q&A

      Mar 23, 2023 · See my article for saving an image to a database, there are three different versions, using EF Core, Dapper or SqlClient. Source code is done in Windows Forms but all the database code is in …

    • Saving images in database using ASP.NET FileUpload …

      Apr 29, 2009 · There are two ways to store images in database either you store image URLs in database as normal string or you store image as binary data. In this …

    • ASP.NET: Insert and Retrieve images using C# and SQL …

      Apr 5, 2021 · This article will learn how to insert and retrieve images in an ASP.NET application backed by a SQL Server database, using the C# language. …

    • File Handling in ASP.NET Core MVC - Dot Net Tutorials

      This ASP.NET Core MVC Product Management Application demonstrates a structured approach to Implement File Handling, which includes efficiently …

    • Saving Images to SQL Server with ASP.NET and ADO.NET

      Nov 14, 2025 · Learn how to upload, store, and retrieve images from a SQL Server database using ASP.NET and ADO.NET, including table design, byte [] handling, and streaming images back to the …

    • Upload Image to Database with ASP.NET Core - GitHub

      Upload Image to Database with ASP.NET Core. Contribute to arifnurdiansyah92/ImageToDb development by creating an account on GitHub.

    • People also ask
      Loading
      Unable to load answer