sqlbulkcopy - Sqlbulk copy truncates first column records -
please trying make bulk copy excel sheet sql server. done first column records truncated, replacing second column records. leaves last column records null. enter image description here
[the sql table][the excel sheet]
below codes used;
dim koneksi_excel new system.data.oledb.oledbconnection("provider=microsoft.ace.oledb.12.0; data source='" & textbox1.text & " '; extended properties=""excel 12.0 xml;hdr=yes; imex=1""")
koneksi_excel.open() dim query_excel string = "select * [sheet1$]" dim cmd oledbcommand = new oledbcommand(query_excel, koneksi_excel) dim rd oledbdatareader dim koneksi new sqlconnection() if mysqlconnectionstring.state = connectionstate.closed mysqlconnectionstring.open() end if using bulkcopy sqlbulkcopy = new sqlbulkcopy(mysqlconnectionstring) 'koneksi bulkcopy.destinationtablename = "dbo.contacttb" try rd = cmd.executereader bulkcopy.writetoserver(rd) rd.close() ' koneksi.close() metromessagebox.show(me, "data import succesful", "done!!", messageboxbuttons.ok, messageboxicon.information) textbox1.text = "" dim da new sqldataadapter dim ds new dataset dim gets string = "select * contacttb" da.selectcommand = new sqlcommand(gets, mysqlconnectionstring) da.fill(ds, "contacttb") metrogrid1.datasource = ds.tables(0) catch ex exception messagebox.show(ex.tostring) mysqlconnectionstring.close() end try end using
Comments
Post a Comment