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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:27:54+00:00 2026-05-26T12:27:54+00:00

I have an error that I can’t fix … I really don’t know why

  • 0

I have an error that I can’t fix … I really don’t know why .

I’m using this code tu upload a file in my database, i want to use the BLOB now .

if (FileUpload1.HasFile)
                    try
                    {

                        //FileUpload1.SaveAs("C:\\inetpub\\wwwroot\\ClientPortalCs\\"
                        //+ GetTheCurrentDirectory(MyTreeView.SelectedNode)
                        //+ "\\" + FileUpload1.FileName);
                        //LabelFile.Text = "File name: " +
                        //FileUpload1.PostedFile.FileName + "<br>" +
                        //FileUpload1.PostedFile.ContentLength + " kb<br>" +
                        //"Content type: " + FileUpload1.PostedFile.ContentType;

                        dbConnection.Open();
                        dynamic queryString = ("INSERT INTO Files (Name,Path,UserUpload,Date,Data) VALUES ('"
                        + FileUpload1.FileName + "','" + GetTheCurrentDirectory(MyTreeView.SelectedNode) + "','" + Request.Cookies["UserSettings"]["UserName"] + "','" + DateTime.Now + "','" + FileUpload1.FileBytes + "' );"
                        + "SELECT CAST(scope_identity() AS int)");

                        SqlCommand theCommand1 = new SqlCommand(queryString, dbConnection);

                        int newFid = (Int32)theCommand1.ExecuteScalar();

                        dynamic queryStringFolder = ("INSERT INTO FILES_FOLDERS (Folder_Id,File_Id) VALUES ('"
                        + MyTreeView.SelectedValue + "'," + "'" + newFid + "')");
                        theCommand1 = new SqlCommand(queryStringFolder, dbConnection);

                        theCommand1.ExecuteNonQuery();

                        dbConnection.Close();

                    }

In my database the field DATA in the table files is a varbinary(max) .
The parameter for DATA field in the query is the bytes of the file I try to upload .

The error occured is :
“Error Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. “

Can someone tell me why ?

Thank you very much .

  • 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-26T12:27:54+00:00Added an answer on May 26, 2026 at 12:27 pm

    The problem, I think, is that you are passing in the byte [] of your image as a string because you are enclosing it in single quotes.

    Remove the single quotes around here:

    '" + FileUpload1.FileBytes + "'"
    

    One more recommendation: Use parameters for your queries. You’ll save yourself from sql injection attacks, your queries may run faster and you’ll eliminate this kind of mistakes in the future.

    UPDATE – using parameters:

    string queryString = "INSERT INTO Files (Name,Path,UserUpload,Date,Data) VALUES (@Name,@Path,@UserUpload,@Date,@Data)";
    SqlCommand theCommand1 = new SqlCommand(queryString, dbConnection);
    theCommand1.Parameters.AddWithValue("@Name",FileUpload1.FileName);
    theCommand1.Parameters.AddWithValue("@Path",GetTheCurrentDirectory(MyTreeView.SelectedNode));
    theCommand1.Parameters.AddWithValue("@UserUpload",Request.Cookies["UserSettings"]["UserName"]);
    theCommand1.Parameters.AddWithValue("@Data",FileUpload1.FileBytes);
    theCommand1.Parameters.AddWithValue("@Date",DateTime.Now);
    
    int newFid = (Int32)theCommand1.ExecuteScalar();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an error that we can't seem to find and don't have the
I have a error that I can not get rid of, but the code
Very basic question, but I have an error in my code that can only
This is a really nebulous error that I can't seem to get a lot
I have this error that is keeping me from moving forward. I basically have
I have a really frustrating error that I've spent hours looking at and cannot
Hi have made this function which is made to replicate an error that I
I have been getting an error message that I can't resolve. It originates from
I have an error that I kind of understand, but can't figure out to
I have run into a pretty strange error that I can't get my head

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.