Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:38:07+00:00 2026-06-06T17:38:07+00:00

Here is my class (product.cs) where is the method to insert the image: public

  • 0

Here is my class (product.cs) where is the method to insert the image:

public static void InsertProductIMG(byte[] image, string contentType) 
{
   string cs = "Data Source=(local);Initial Catalog=myApp;Integrated Security=True";
   string comandoSql = "INSERT INTO [myApp].[dbo].[product] (image, ContentType) VALUES (@image, @contentType)";

   using (SqlConnection conn = new SqlConnection(cs))
   {
       conn.Open();

       using (SqlTransaction trans = conn.BeginTransaction())
       {
           SqlCommand cmd = new SqlCommand(comandoSql, conn, trans);
           SqlParameter[] parms = new SqlParameter[2];
           parms[0] = new SqlParameter("@image", image);
           parms[1] = new SqlParameter("@contentType", contentType);
           foreach (SqlParameter p in parms)
           {
              cmd.Parameters.Add(p);
           }

           cmd.ExecuteNonQuery();
           trans.Commit();
       }
    }
}

Here is the code behind of the apsx page where I call the method above:

byte[] imageBytes = new byte[fupld.PostedFile.InputStream.Length];
product.InsertProductIMG(imageBytes, "image/jpeg");//product is the class where the method is

Now I’d like to know how can I display this image?

Would I have to read the byte[] from sql (SELECT), convert to string and so convert to byte[]? And after do that convert to bitmap (System.Drawing). But how I show this bitmap in a aspx page?

I’ve no idea how to do it. Please help!! :]

Thanks

Obs.: In SQL Server, the column image is of type varbinary(MAX).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:38:10+00:00Added an answer on June 6, 2026 at 5:38 pm

    Create a web page that returns the image. You would select the bytes from the database (as you have already code written to insert, I think you know how to select). Once you have the bytes, you need to set the mime type and write the bytes to the response stream.

    var bytesFromDatabase = getImageFromDatabase();
    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(bytesFromDatabase);
    

    Edit:

    Just use a img tag with the cource tet to the aforementioned aspx web page. Eg:

    <img src="http://www.example.com/image.aspx?id=1" alt="image" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of All here's the Codes: Product Information: public class ProductInformation { public String
I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{
I have a product.aspx class public partial class _Products : Product { protected void
I have some HTML that looks like this: <div class=product> Content In Here <div
I have this simple js tabs. Here is the html : <div class=product-collateral> <div
I have the following class: public class Product { public virtual Guid Id {
I have a model like this defined... public class Product{ private long timestamp; //
Here are my classes : class PriceScale -int ID -float bookingFees -Product product -List<PricePeriod>
I found this code here class Usable; class Usable_lock { friend class Usable; private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.