Buena noches estimados compañeros,
Hice un botón para poder abrir un archivo pdf el cual ya lo tengo guardado en una base de datos como binarios largos, el programa que hice es este:
Private Sub AbrirPDF()
Dim consultacatalogo As String
Dim abrir As String
Dim lista As Byte()
consultacatalogo = "SELECT * FROM Catalogo Where Código = '" & TextC.Text & "'"
Dim mostrar As OleDbCommand = New OleDbCommand(consultacatalogo, conexion)
lista = mostrar.ExecuteScalar
abrir = System.IO.Path.GetTempFileName()
File.Move(abrir, Path.ChangeExtension(abrir, ".pdf"))
abrir = System.IO.Path.ChangeExtension(abrir, ".pdf")
File.WriteAllBytes(abrir, lista)
Dim act As Action(Of String) = New Action(Of String)(AddressOf MostrarPDF)
act.BeginInvoke(abrir, Nothing, Nothing)
End Sub
Public Shared Sub MostrarPDF(ByVal abrir)
Using p As New Process
p.StartInfo = New ProcessStartInfo(abrir)
p.Start()
p.WaitForExit()
Try
File.Delete(abrir)
Catch ex As Exception
End Try
End Using
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AbrirPDF()
End Sub
Y cuando doy click en el boton, me sale el siguiente error:
An unhandled exception of type 'System.InvalidCastException' occurred in GMP Ingenieros.exe
Additional information: No se puede convertir un objeto de tipo 'System.String' al tipo 'System.Byte[]'.
Exactamente en esta línea:
lista = mostrar.ExecuteScalar
He intentado de varias formas, pero no lo he logrado, por favor necesito de vuestra ayuda.