How to display mysql blob image in asp.net image control?

后端 未结 2 1127
终归单人心
终归单人心 2020-12-20 03:00

I known the way to display the mysql blob image in Windows Forms.

try
            {
                MySqlConnection connection = new MySqlConnection(hp.myCo         


        
2条回答
  •  时光取名叫无心
    2020-12-20 03:02

    What you're trying to do doesn't make sense: the browser trying to display your image will need to know where to download it from.

    You should setup a special aspx page, dedicated to image generation, for example GetImage.aspx.

    Your main page will then have img html tags pointing to this image generation page:

    
    

    Then, inside GetImage.aspx, you retrieve the image from DB according to its id (fetched from URL parameter). The code would be something like:

    command = connection.CreateCommand();
            command.CommandText = "Select FO_Roomdet_Image from fo_roomtype where FO_Roomdet_Id=1"; // or dynamically fetch id with Request.QueryString and properly escape it
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
    
                Response.ContentType = "image/jpeg"; // if your image is a jpeg of course
                Response.BinaryWrite((byte[])Reader.GetValue(0));                                 
            }
            connection.Close();
    

提交回复
热议问题