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 1018403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:51:08+00:00 2026-05-16T10:51:08+00:00

I am saving a image into database with byte[] property like this: ProfileModel: private

  • 0

I am saving a image into database with byte[] property like this:

ProfileModel:

private byte[] _imageData;

public byte[] ImageData
{
    get
    {
        return _imageData;
    }
    set
    {
        _imageData = value;
    }
}

When I am trying to read image i have problem with converting of byte. I dont know how to convert reader into byte[]. I thought that its enough to convert.ToByte, but it doesnt works.

ThreadModel:

private byte _imageData;
public byte ImageData
{
    get
    {
        return _imageData;
    }
    set
    {
        _imageData = value;
    }
}

Its my method where I am reading image information:

cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @"SELECT ImageData, " 
                 + " ContentType, " 
                 + " ImageName " 
                 + " FROM UsersImage "
                 + " WHERE UserName = @UserName ";

cmd.Parameters.AddWithValue("@UserName", ThreadUserName);

reader = cmd.ExecuteReader();
if (reader.Read())
{
    if (reader["ContentType"] != DBNull.Value)
    {
        ContentType = Convert.ToString(reader["ContentType"]);
    }

    if (reader["ImageName"] != DBNull.Value)
    {
        ImageName = Convert.ToString(reader["ImageName"]);
    }

    if (reader["ImageData"] != DBNull.Value)
    {
        ImageData = Convert.ToByte(reader["ImageData"]);
    }

    int affectedRows = cmd.ExecuteNonQuery();
    if (affectedRows != 1)
    {

    }
}
reader.Close();
  • 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-05-16T10:51:08+00:00Added an answer on May 16, 2026 at 10:51 am
    byte[] buffer = new byte[reader.GetBytes(reader.GetOrdinal("ImageData"), 0, null, 0, int.MaxValue)];
    reader.GetBytes(reader.GetOrdinal("ImageData"), 0, buffer, 0, int.MaxValue);
    

    Might work, untested though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would try quoting all of the parameters, for example:… May 16, 2026 at 10:52 am
  • Editorial Team
    Editorial Team added an answer Try using a TransitioningContentContol instead of a ContentControl. How-to Video… May 16, 2026 at 10:52 am
  • Editorial Team
    Editorial Team added an answer You are making them required by setting eform on all… May 16, 2026 at 10:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

i need to get an image from client and displayed(preview) before saving it into
I'm going to be saving images into an SQL Database (don't know what type
I have uploaded a text file to my database into a Image field. The
I've got a richtextbox, that I plan on saving to a database, which can
I have a JPEG image (actually a BLOB in a database) which I want
I have the following object: [Serializable] public class ExampleImage { public int ID {
This seems to be in infamous error . I remember getting it a while
I have been pulling my hair out about this since Friday and I am
Am i correct in saying a 16 bit image will be decode and drawn
I am working on an application where i am saving the state of an

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.