I have this button that when the user click all data from postgres will download to excel. i found the reference but the problem is its C# http://www.sqlines.com/postgresql/npgsql_cs_result_sets
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim dt As New DataTable
Try
Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=YouthRecord;server=localhost;port=5432;uid=*****;sslmode=disable;readonly=0;protocol=7.4;User ID=*****;password=*****;"),
cmd As New Odbc.OdbcCommand("SELECT * FROM ""YouthApp_table_residencedata"" ", MyCon)
MyCon.Open()
dt.Load(cmd.ExecuteReader)
???????
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
UPDATE did i do it right? can you point out the mistake I made here?
Dim dt As New DataTable
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add
oSheet = oBook.Worksheets(1)
'Create the QueryTable
Dim sNWind As String
Dim oQryTable As Object
sNWind = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
Try
Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=YouthRecord;server=localhost;port=5432;uid=postgres;sslmode=disable;readonly=0;protocol=7.4;User ID=postgres;password=ncf123;"),
cmd As New Odbc.OdbcCommand("SELECT * FROM ""YouthApp_table_residencedata"" ", MyCon)
MyCon.Open()
dt.Load(cmd.ExecuteReader)
oQryTable = oSheet.QueryTables.Add(MyCon, oSheet.Range("A1"), dt)
oQryTable.Refresh
'Save the Workbook and Quit Excel
oBook.SaveAs("C:\Users\Kevin Trinidad\Documents\Residence.xls")
oExcel.Quit
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
this is the error i received
Exception thrown: 'System.ArgumentException' in Microsoft.VisualBasic.dll
'local.exe' (CLR v4.0.30319: local.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'.
The program '[39712] local.exe' has exited with code -1 (0xffffffff).