vb.net - An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll -



vb.net - An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll -

i create project vb.net export info excels. error unhandled exception of type 'system.data.odbc.odbcexception' occurred in system.data.dll

i connect database postgresql utilize postgresql odbc driver (psqlodbc).

mainform.vb

imports system.io imports system.data imports system.data.odbc public class mainform private function getdemodataset() dataset dim mycon new odbc.odbcconnection mycon.connectionstring = "driver={postgresql unicode};database=tscon;server=192.168.3.60;port=5432;uid=postgres;sslmode=disable;readonly=0;protocol=7.4;user id=postgres;password=1234;" dim da odbc.odbcdataadapter dim dt new datatable() dim str2 string mycon.open() str2 = "select * entity_tbl" dim ds new dataset da = new odbc.odbcdataadapter(str2, mycon) da.fill(ds) ds.tables(0).tablename = "customer0" mycon.close() homecoming ds end function private sub startdemobutton_click(byval sender system.object, byval e system.eventargs) handles startdemobutton.click ' prepare output filenames dim timemark string = datetime.now.tostring("yyyymmdd hhmmss") ''dim cellbycellfilepath string = "c:\excelexportcellbycell_" + timemark + ".xls" dim fastexportfilepath string = "d:\" + timemark + ".xls" me.demoresultlistbox.items.clear() ' object mark times each process dim stopwatch new stopwatch() me.usewaitcursor = true seek ' demo dataset stopwatch.start() dim demodataset dataset = me.getdemodataset() stopwatch.stop() me.demoresultlistbox.items.add("* generate demo dataset: " + stopwatch.elapsed.tostring()) stopwatch.reset() ' '' utilize "copy-cell-by-cell" method ''stopwatch.start() ''exportingcellbycellmethod.exporttoexcel(demodataset, cellbycellfilepath) ''stopwatch.stop() ''me.demoresultlistbox.items.add("* re-create cell-by-cell method: " + stopwatch.elapsed.tostring()) ''stopwatch.reset() ' utilize "fast export" method stopwatch.start() fastexportingmethod.exporttoexcel(demodataset, fastexportfilepath) stopwatch.stop() me.demoresultlistbox.items.add("* fast export method: " + stopwatch.elapsed.tostring()) stopwatch.reset() me.usewaitcursor = false end seek end sub end class

module fastexportingmethod.vb

imports microsoft.office.interop.excel imports microsoft.office.interop module fastexportingmethod public sub exporttoexcel(byval dataset dataset, byval outputpath string) ' create excel application object 'dim excelapp new applicationclass() dim excelapp new excel.application() ' create new excel workbook dim excelworkbook workbook = excelapp.workbooks.add(type.missing) dim sheetindex integer = 0 dim col, row integer dim excelsheet worksheet ' re-create each datatable new sheet each dt system.data.datatable in dataset.tables sheetindex += 1 ' re-create datatable object array dim rawdata(dt.rows.count, dt.columns.count - 1) object ' re-create column names first row of object array col = 0 dt.columns.count - 1 rawdata(0, col) = dt.columns(col).columnname next ' re-create values object array col = 0 dt.columns.count - 1 row = 0 dt.rows.count - 1 rawdata(row + 1, col) = dt.rows(row).itemarray(col) next next ' calculate final column letter dim finalcolletter string = string.empty dim colcharset string = "abcdefghijklmnopqrstuvwxyz" dim colcharsetlen integer = colcharset.length if dt.columns.count > colcharsetlen finalcolletter = colcharset.substring( _ (dt.columns.count - 1) \ colcharsetlen - 1, 1) end if finalcolletter += colcharset.substring( _ (dt.columns.count - 1) mod colcharsetlen, 1) ' create new sheet excelsheet = ctype( _ excelworkbook.sheets.add(excelworkbook.sheets(sheetindex), _ type.missing, 1, xlsheettype.xlworksheet), worksheet) excelsheet.name = dt.tablename ' fast info export excel dim excelrange string = string.format("a1:{0}{1}", finalcolletter, dt.rows.count + 1) excelsheet.range(excelrange, type.missing).value2 = rawdata ' mark first row bold ctype(excelsheet.rows(1, type.missing), range).font.bold = true excelsheet = nil next ' save , close workbook excelworkbook.saveas(outputpath, xlfileformat.xlworkbooknormal, type.missing, _ type.missing, type.missing, type.missing, xlsaveasaccessmode.xlexclusive, _ type.missing, type.missing, type.missing, type.missing, type.missing) excelworkbook.close(true, type.missing, type.missing) excelworkbook = nil ' release application object excelapp.quit() excelapp = nil ' collect unreferenced objects gc.collect() gc.waitforpendingfinalizers() end sub end module

vb.net postgresql-9.1

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -