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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:40:38+00:00 2026-06-13T14:40:38+00:00

hi i have web application in which i need to store image into one

  • 0

hi i have web application in which i need to store image into one of column of datatble
but i am getting error when doing this.Here is my code i tried for this.

DataTable dt = new DataTable();

dt.Columns.Add("Companyaddress", typeof(System.String));
dt.Columns.Add("CompEmail", typeof(System.String));
dt.Columns.Add("CompTelephone", typeof(System.String));
dt.Columns.Add("logoname", typeof(byte[]));
//dt.Columns.Add("logoname", typeof(System.Byte[]));

for (int rowNumber = 0; rowNumber < imageDataSet.Tables[0].Rows.Count; rowNumber++)
{
    imageDataSet.Tables[0].Rows[rowNumber]["logoname"] = GetByteArray("abc.jpg");
    dt.Rows.Add(imageDataSet.Tables[0].Rows[rowNumber][0].ToString(), 
                imageDataSet.Tables[0].Rows[rowNumber][1].ToString(), 
                imageDataSet.Tables[0].Rows[rowNumber][2].ToString(), 
                imageDataSet.Tables[0].Rows[rowNumber][3].ToString());
 }

Getting error

Type of value has a mismatch with column typeCouldn’t store
in logoname Column. Expected type is Byte[].

on this line

dt.Rows.Add(imageDataSet.Tables[0].Rows[rowNumber][0].ToString(), imageDataSet.Tables[0].Rows[rowNumber][1].ToString(), imageDataSet.Tables[0].Rows[rowNumber][2].ToString(), imageDataSet.Tables[0].Rows[rowNumber][3].ToString());

This is functon i call to get image

private byte[] GetByteArray(String strFileName)
{
    System.IO.FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.Open);
    // initialise the binary reader from file streamobject
    System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
    // define the byte array of filelength

    byte[] imgbyte = new byte[fs.Length + 1];
    // read the bytes from the binary reader

    imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
    // add the image in bytearray

    br.Close();
    // close the binary reader

    fs.Close();
    // close the file stream
    return imgbyte;
}

what to do? need help.

  • 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-13T14:40:39+00:00Added an answer on June 13, 2026 at 2:40 pm

    Problem is the way you are adding the row the DataTable.

    You should use:

    dt.Rows.Add(imageDataSet.Tables[0].Rows[rowNumber][0].ToString(),
        imageDataSet.Tables[0].Rows[rowNumber][1].ToString(), 
        imageDataSet.Tables[0].Rows[rowNumber][2].ToString(), 
        imageDataSet.Tables[0].Rows[rowNumber][3] as byte[]);
    

    Since your Column 3 corresponds to the byte array field, you may cast it to byte[] type. Earlier you were using .ToString whereas the method was expecting a byte[] type argument. Hence the exception.

    For clarity, you may re-write your loop using DataTable.NewRow as:

    for (int rowNumber = 0; rowNumber < imageDataSet.Tables[0].Rows.Count; rowNumber++)
    {
        imageDataSet.Tables[0].Rows[rowNumber]["logoname"] = GetByteArray("abc.jpg");
        DataRow dr = dt.NewRow();
        dr["Companyaddress"] = imageDataSet.Tables[0].Rows[rowNumber][0].ToString();
        dr["CompEmail"] = imageDataSet.Tables[0].Rows[rowNumber][1].ToString();
        dr["CompTelephone"] = imageDataSet.Tables[0].Rows[rowNumber][2].ToString();
        dr["logoname"] = imageDataSet.Tables[0].Rows[rowNumber][3] as byte[];
        dt.Rows.Add(dr);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one web application which I have been working for some time.I am
I have two web applications which need to show products' images, but how to
We have a web application which needs to store uploaded images with EdgeCast or
I'm writing a web application in PHP which needs to store images and image
We are currently doing an web application which one of the functionality is to
we store image files into database as BLOB type, but i have to save
I have web application which we deployed in a production . We have separate
I have web application of which major part is javascript. I request images from
I have a web application which process the data collected from different client machines
I have a web application which uses the globalization values being passed from sql

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.