Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Windows MySQL VB.NET
Hi all
I wrote the below code to print the data table in a pdf file
Dim strFilePath As String
        Dim stm As StreamWriter
        Dim i As Integer
        con = New MySqlConnection("Server=localhost; Database=demo;Uid=root; password=1234")
        Dim cmd As MySqlCommand = New MySqlCommand("select * from demodata", con)
        Dim dt As DataTable = New DataTable()
        Dim da As MySqlDataAdapter = New MySqlDataAdapter(cmd)
        '  DataGridView1.DataSource = dt
            strFilePath = "C:\a\test.pdf"
            stm = New StreamWriter(strFilePath, False)
            For i = 0 To dt.Columns.Count - 2
                stm.Write(dt.Columns(i).ColumnName + ControlChars.Tab)
            Next i
            For Each row As DataRow In dt.Rows
                Dim array() As Object = row.ItemArray
                For i = 0 To array.Length - 2
                    stm.Write(array(i).ToString() + ControlChars.Tab)
                Next i
            Next row
            'File.Open(strFilePath, vbReadOnly)
            MsgBox("job done!")
        Catch ex As Exception
        End Try
the problem is it's creating the pdf file but when i m opening it's giving error saying file damaged or not supported file type.
Please tell me the problem..
Posted 3-Jan-13 2:14am
Zoltán Zörgő at 3-Jan-13 13:05pm
Sorry, I have pasted the wrong link. See update!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

StreamWriter ?!?!?!, are you writing your pdf by hand?
Of course you get error. You shouldn't go this way...
Use an external component like the ones listed here:[^]
[Update(zorgoz): link changed to the right one]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you can use any reporting tool for the same, using it you can easily export to pdf
Smile | :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 768
1 OriginalGriff 420
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445

Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100