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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:24:02+00:00 2026-06-05T07:24:02+00:00

I try to download a photo from the database. In database, the field type

  • 0

I try to download a photo from the database. In database, the field type is Image.
The ID is type UniqueIdentifier.
My code

public void ProcessRequest (HttpContext context) {
    ConnectTodatabase conection = new ConnectTodatabase();
    conection.makeConnection();

    // Create SQL Command 
    SqlCommand cmd = new SqlCommand("Select ID,photo from profile where ID=@ID", conection.Connection);
    SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.UniqueIdentifier);
    ImageID.Value = context.Request.QueryString["ID"];
    cmd.Parameters.Add(ImageID);

    SqlDataReader dReader = cmd.ExecuteReader();
    dReader.Read();
    context.Response.BinaryWrite((byte[])dReader["photo"]);
    dReader.Close();


    context.Response.ContentType = "text/plain";
    context.Response.Write("test 123456");
}

The Exception is InvalidCastException. “Failed to convert parameter value from a String to a Guid.”
How to pass ImageID to correct type?
Thanks!!!

call handler

foreach (DataRow theRow in thisDataSet.Tables["Profile"].Rows)
        {
            resultCounter++; 
            double x, y;
            x = Convert.ToDouble(theRow["lat"]);
            y = Convert.ToDouble(theRow["lng"]);
            string id = Convert.ToString(theRow["ID"]);
            GLatLng latlng = new GLatLng(x, y);//sintetagmenes shmeiou
            //dimiourgia ton 2 ipomenou gia kathe shmeio
            GInfoWindowTabs iwTabs = new GInfoWindowTabs();
            iwTabs.point = latlng;

            System.Collections.Generic.List<GInfoWindowTab> tabs = new System.Collections.Generic.List<GInfoWindowTab>();

            tabs.Add(new GInfoWindowTab("Profile Info:", "<table> <tr> <td><b>Name: </b> </td><td>" + theRow["fname"] + "</td></tr><tr><td><b>Lastname: </b></td><td>" + theRow["lname"] + "</td></tr><tr><td><b>Affiliation: </b></td><td>" + theRow["affiliation"] + "</td></tr><tr><td><b>Address: </b></td><td>" + theRow["address"] + "</td></tr><tr><td><b>Country: </b></td><td>" + theRow["country"] + "</td></tr><tr><td><b>Email: </b></td><td>" + theRow["email"] + "</td></tr><tr><td><b>Role: </b></td><td>" + theRow["role"]));


            tabs.Add(new GInfoWindowTab("Profile Photo:", "<img src=Handler.ashx?ID=" + theRow["ID"] + "border=1>"));
  • 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-05T07:24:03+00:00Added an answer on June 5, 2026 at 7:24 am

    Try this and see if it works:

    SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.UniqueIdentifier);
    ImageID.Value = System.Data.SqlTypes.SqlGuid.Parse(context.Request.QueryString["ID"]);
    

    The key here is in converting the string to a GUID.

    EDIT

    I noticed that the edit you made includes your call handler. Two glaring issues I see with your call handler is that you created an id variable to hold your converted GUID, but you aren’t acually using it. Also, you aren’t properly delimiting your border query parameter using the ampersand: &

    Change this:

    tabs.Add(new GInfoWindowTab("Profile Photo:", "<img src=Handler.ashx?ID=" + theRow["ID"] + "border=1>"));
    

    to this:

    tabs.Add(new GInfoWindowTab("Profile Photo:", "<img src=Handler.ashx?ID=" + id + "&border=1>"));
    

    So, in essence, you are sending this as your ID: 5a6b4047-e2dc-40d8-9c58-8609278154f4border=1 which isn’t a valid GUID.

    Just as a tip, I would have done it like this which would have likely made it easier to spot your Type-O:

    tabs.Add(new GInfoWindowTab("Profile Photo:", string.Format("<img src=Handler.ashx?ID={0}&border=1>", id)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am try to download image files from url from the following code, but
When I have download sample code from this link and than try to build
when i try to download a image from my iPhone (Drop Pin Marker) through
I try to download an image with this code and save it : in
When I try to download a project from Google Code using TortoiseHg I got
I try to download an image from my django website. I do it like
I m using this code and try to download an png pic from server
i'm download DrillDownApp example project from iPhoneSDKArticles i have a problem when i'm try
I am using the api twitterizer2 downloaded from http://code.google.com/p/twitterizer/downloads/list but when I try to
Hi I have this code to download images from the server and then to

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.