sql server - Malfunction of data copy from excel to Sql using BulkCopy (vb.net) -
i'm searching reason why importation excel sql table not working (via vb.net)
the excel file in input contains 1300 rows , 12 columns. 5 last columns contains prices. after importation, table if filled excel data except 2 last "price" columns data 'null'. strange thing "price" columns in sql destination table formatted same type (decimal(18,2)), in excel file. copy, use sqlbulkcopy , wonder if function not limited.
here's code:
dim excelconnection new system.data.oledb.oledbconnection("provider=microsoft.ace.oledb.12.0;data source=" & ftransp & ";extended properties=""excel 12.0 xml;hdr=yes""") excelconnection.open() dim requeteexceltransp string = "select * [excelcetup$]" dim objcmdselect oledbcommand = new oledbcommand(requeteexceltransp, excelconnection) dim objdr oledbdatareader using bulkcopy sqlbulkcopy = new sqlbulkcopy(connexionlinkystat) bulkcopy.destinationtablename = "dbo." & tabletransp & "" try objdr = objcmdselect.executereader bulkcopy.writetoserver(objdr) objdr.close() connexionlinkystat.close() catch ex exception msgbox(ex.tostring) end try end using excelconnection.close()
i trying 1 code, hope code helpful project
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click
dim myconnection system.data.oledb.oledbconnection dim dtset system.data.dataset dim mycommand system.data.oledb.oledbdataadapter dim fbrowse new openfiledialog fbrowse .filter = "excel files(*.xlsx)|*.xlsx|all files (*.*)|*.*" .filterindex = 1 .title = "import data excel file" end if fbrowse.showdialog() = windows.forms.dialogresult.ok dim fname string fname = fbrowse.filename myconnection = new system.data.oledb.oledbconnection("provider=microsoft.ace.oledb.12.0; data source='" & fname & " '; " & "extended properties=excel 8.0;") mycommand = new system.data.oledb.oledbdataadapter("select * [sheet1$]", myconnection) mycommand.tablemappings.add("table", "test") dtset = new system.data.dataset mycommand.fill(dtset) myconnection.close() each drr datarow in dtset.tables(0).rows execute_local("insert excel(name, designation, salary) values ('" & drr(0).tostring & "','" & drr(1).tostring & "','" & drr(2).tostring & "')") next msgbox("successfully saved") end if end sub`
Comments
Post a Comment