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

  • Home
  • SEARCH
  • 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 8045427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:32:37+00:00 2026-06-05T05:32:37+00:00

I have a table in my database and one of its columns is in

  • 0

I have a table in my database and one of its columns is in Image data type. I can store Image in database but I can’t retrieve it. I want to retrive Image for each logged in user. I used this code:

public ActionResult ShowImage()
{
    var userID = GetUserID();
    var advert = from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage;
    return File(advert, "Image");     
}

But got this error:

Error 2 Argument 1: cannot convert from ‘System.Linq.IQueryable’ to ‘string’ C:\Users\Tena\Documents\Visual Studio 2010\Projects\MvcApplication6\MvcApplication6\Controllers\Default3Controller.cs 92 25 MvcApplication6

The problem is that advert is in

System.Linq.IQueryable<>byte[]

format but File needs byte[] format. What should I do now? Any answer is helpful.

Thanks

  • 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-05T05:32:38+00:00Added an answer on June 5, 2026 at 5:32 am

    The problem is that the LINQ query isn’t being evaluated and the query as it stands could theoretically return more than one result (hence it’s an IQueryable).

    In fact the query doesn’t look right as presumably there will be more than one advert for a particular user and I wouldn’t expect the adverts to be stored according to user in any case, but I don’t know anything about your data structure, so I’ll just try to help you make the query work and you can refine it later.

    Try changing this line:

    var advert = from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage;
    

    to this:

    var advert = (from ad in StoreDb.Ads where ad.UserId == userID select ad.AdImage).FirstOrDefault();
    

    I could give you other tips around how to do this, but try that first and see what happens.

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

Sidebar

Related Questions

I have a database table where one of its columns is of type datetime.
I have one database table which contains 8 columns. One of the columns is
I have to copy a bunch of data from one database table into another.
I have one large database table of request data, much like Apache request logs,
I have loaded my database with one table under Data Connections in the Server
I want to have a database table that keeps data with revision history (like
I have one table in sqlite database which contains five different columns as shown
I have one database table TABLE_TIPS with two value 1. tips_id (auto increment) 2.
I have simple database - one table with 6 collumns. 3 of them i
I have a table in database that is having some fields one of which

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.