jueves, 21 de febrero de 2019

extraer archivo binario sql

Dim con As New SqlConnection(Form1.conex)
        Dim query As String = "select certificado_bin from certificados where id=@id"
        con.Open()
        Using cmd As New SqlCommand(query, con)
            cmd.Parameters.Add("@id", SqlDbType.Int).Value = id

            Using sql_query_result = cmd.ExecuteReader
                If sql_query_result IsNot Nothing Then
                    sql_query_result.Read()
                    Dim blob = New Byte((sql_query_result.GetBytes(0, 0, Nothing, 0, Integer.MaxValue)) - 1) {}
                    sql_query_result.GetBytes(0, 0, blob, 0, blob.Length)
                End If
            End Using
        End Using
        con.Close()

fuente

No hay comentarios.:

Publicar un comentario