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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:58:40+00:00 2026-05-26T22:58:40+00:00

I am trying to save a file to an Image datatype using inline query.

  • 0

I am trying to save a file to an Image datatype using inline query.

INSERT INTO tblPDFInfo(FileImage, PdfFileName, FeedDateTime, HasProcessed)
VALUES(@fileBytes, @fileName, getutcdate(), 0)

and then if I use string.format then it is rendering the byte array to string and so it serves no luck.

Another way if I create a sqlcommand and

   objCmd = new SqlCommand(strSQL, objConn, objTrans);
   objFileDataParam = new SqlParameter("@fileBytes", SqlDbType.Image);
   objFileDataParam.Value = (byte[])fileData;
   objCmd.Parameters.Add(objFileDataParam);

   objFileNameParam = new SqlParameter("@fileName", SqlDbType.VarChar);
   objFileNameParam.Value = PDFfileName;
   objCmd.Parameters.Add(objFileNameParam);
   objCmd.CommandText = strSQL;  

Then when firing the query it is saying

System.Data.SqlClient.SqlException: Must declare the scalar variable
“@fileBytes”

And if in inline query I am declaring the same variable then it too gives me error saying

System.Data.SqlClient.SqlException: The variable name ‘@fileBytes’
has already been declared. Variable names must be unique within a
query batch or stored procedure.

How could I correct this up to make it working. Well I am not bound to a specific datatype but I need to save the file and later on retrieve it too, I think the image datatype would be a good choice, but could not make it happen. Any suggestions would be really helping.

  • 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-26T22:58:41+00:00Added an answer on May 26, 2026 at 10:58 pm

    Try this,

    string strSql="INSERT INTO tblPDFInfo (FileImage,PdfFileName,FeedDateTime,HasProcessed) 
                   values(@fileBytes,@fileName,@getutcdate,@hasprocessed)";
    
    byte []bytes=(byte[])fileData;
    objCmd = new SqlCommand(strSQL, objConn, objTrans);
    objCmd.Parameters.Add("@fileBytes", SqlDbType.Image,bytes.Length).Value=bytes;
    objCmd.Parameters.Add("@fileName", SqlDbType.VarChar,100).Value=PDFfileName;
    objCmd.Parameters.Add("@getutcdate", SqlDbType.DateTime).Value=DateTime.Now;
    objCmd.Parameters.Add("@hasprocessed", SqlDbType.Bit).Value=0;
    
    objCmd.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save a file (pdf or image) uploaded from a form into
I'm trying to save image into sql-server using linq. I set the field type
I'm trying to take an image file, do some stuff to it and save
I'm trying to convert wmf image file into png format with c#.net. But, saved
I am trying to convert a PIL image into an array using NumPy. I
I'm using MagickCore to generate images from scratch. I'm trying to save my Image
I am trying to save image from fileupload control into the database public Byte[]
I am trying to download an 1mb image file and then save to bitmap
Im just trying to save a file to disk using a posted stream from
I'm trying to save an image to my sdcard but running into the following

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.