Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Gramas

Binary Images

Recommended Posts

Gramas

Boas Tardes...

        Dim conn As SqlConnection
        Dim cmd As New SqlCommand
        Dim sql As String
        Dim dr As SqlDataReader
        Dim connstr As String = ConfigurationManager.ConnectionStrings("TestesConnectionString").ConnectionString
        conn = New SqlConnection(connstr)
        conn.Open()
        cmd.Connection = conn

        sql = "SELECT * FROM Images "

        cmd.CommandText = sql
        dr = cmd.ExecuteReader

        Response.Clear()

        If dr.Read Then
            Response.ContentType = dr.Item("Imagens").ToString
            Response.OutputStream.Write(dr("Imagens"), 0, dr("Imagens"))
        End If
        Response.End()


        conn.Close()

Tenho Este codigo para mostrar uma imagem da base de dados que esta com datatype como binary, mas nao me resulta em nada :confused:

O que estou a fazer de mal?

Obrigado pessoal.

Share this post


Link to post
Share on other sites
Gramas

Response.OutputStream.Write(dr("Imagens"), 0, dr("Imagens"))

Nesta linha diz que e impossivel a conversao de nyte para int...

Share this post


Link to post
Share on other sites
vitortomaz

o que é que está a ir em content type?

tens que meter a imagem num byte[] tipo binaryWrite = ((byte[])dr["imageData"]);

e depois escreve-lo para o stream

if (_binaryWrite != null)

            {

                response.ContentType = _contentType;

                response.BinaryWrite(_binaryWrite);

            }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.