1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString =
"server=localhost;userid=root;password=root;database=root"
' recuperamos el documento de la base de datos y lo pasamos a un fichero
Dim drDocumentos As MySqlDataReader
Dim aBytDocumento() As Byte = Nothing
'Dim oFileStream As FileStream
'Dim loFila As DataGridViewRow = Me.dgrDatos.CurrentRow()
Dim lsQuery As String = "Select documento From Formaciones Where id='" & TextBox9.Text & "'"
Using loComando As New MySqlCommand(lsQuery, MysqlConn)
MysqlConn.Open()
drDocumentos = loComando.ExecuteReader(CommandBehavior.SingleRow)
End Using
Dim saveFileDialog1 As New SaveFileDialog
saveFileDialog1.InitialDirectory = "C:\"
saveFileDialog1.Title = "Save PDF Files"
saveFileDialog1.CheckFileExists = True
saveFileDialog1.CheckPathExists = True
saveFileDialog1.DefaultExt = "pdf"
saveFileDialog1.Filter = "Text files (*.pdf)|*.pdf"
saveFileDialog1.FilterIndex = 2
saveFileDialog1.RestoreDirectory = True
If drDocumentos.Read() Then
aBytDocumento = CType(drDocumentos("documento"), Byte())
End If
'drDocumentos.Close()
'oFileStream = New FileStream("C:\TUCARPETA\TUFICHERO.PDF", FileMode.CreateNew, FileAccess.Write)
'oFileStream.Write(aBytDocumento, 0, aBytDocumento.Length)
'oFileStream.Close()
MessageBox.Show("Documento generado con éxito", "Generar Documentos", MessageBoxButtons.OK, MessageBoxIcon.Information)
'End If
Catch Exp As Exception
MessageBox.Show(Exp.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub |
Partager