how to update and display an image using sql server and RRS feed

  • Question

  • This is my table in sql where here I send to call my image as image type:

        create table registro(id int IDENTITY(1,1),Nombre varchar(100),numero_control varchar(100),appaterno 
        apmaterno varchar(100),lineainvestigacion varchar(100),
        correo varchar(100),correoi varchar(100),telefonop varchar(100),extension varchar(100),telefonoof 
        usuario varchar(100) PRIMARY KEY ,clave varchar(100),imagen image,idrol varchar(100),ciudadr 

    This is my class where here I send to call my image as byte type

        public class Registro1{
          public byte[] Imagen { get; set; }
          public string usuario {get;set;}

    In if I would like the image to both be updated and show like this sql syntax:    

         select Imagen from registro Where usuario='lalomiguel';

    I would like to know how to update the image and display the image occupying mvc as I am new to this, I am ocupping .cshtml

    • Edited by Lalo Miguel Thursday, May 6, 2021 8:13 PM error de dias pasados
    Thursday, May 6, 2021 8:11 PM

All replies

  • You can use this code, and it may help you to solve this query
    Public Function show-Image(empid As Int32) As Byte()
       Dim myconnection As New SqlConnection('Server=localhost;uid=sa;password=;database=northwind;')
       Dim mycommand As New SqlCommand('Select Employeeid, FirstName,Photo from Employees where employeeid =' + empid.ToString(), myconnection)
       Dim dr As SqlDataReader = mycommand.ExecuteReader()
       Dim imgbyte As Byte() = CType(dr('Photo'), Byte())
       Return imgbyte
    End Function 'showImage 
    In Page_Load
    Dim data As Byte() = showImage(2)
    Dim offset As Int32 = 78

    Dim mstream As New System.IO.MemoryStream()

    mstream.Write(data,offset,data.Length -offset)
    Dim bmp As New System.Drawing.Bitmap(mstream)
    bmp.Save(Server.MapPath('beispiel.jpeg'), System.Drawing.Imaging.ImageFormat.Jpeg)
    Image1.ImageUrl = Server.MapPath('muster.jpeg')


    Saturday, May 8, 2021 9:09 AM
  • Thanks for the info.
    Wednesday, May 12, 2021 7:09 AM