VB.NET Update to Excel -



VB.NET Update to Excel -

i developing application in visual basic using visual studio 2013. in application attempting utilize oledb update write info out excel spreadsheet treated database. have tried numerous different formats of either syntax error or pretends work nil gets written file. can tell me wrong code:

public function writetoexcel(excelpath string, dtuser datatable)

dim voffice string = dtuser.rows(0).item("office").tostring dim vdivision string = dtuser.rows(0).item("division").tostring dim vsection string = dtuser.rows(0).item("section").tostring dim vuser string = dtuser.rows(0).item("userid").tostring dim excelconnstring string = "provider=microsoft.ace.oledb.12.0;data source=" & excelpath & ";extended properties='excel 12.0 xml;hdr=yes';" dim batchid long = 0 dim sql string = "update [installationreport$] set office = @uoffice [primary user] = @uuser" 'dim sql string = "update [installationreport$] set office = @uoffice, " & _ '"division = @udivision, " & _ '"section = @usection " & _ '"where [primary user] = @uuser" using conn new oledb.oledbconnection(excelconnstring) dim cmd new oledb.oledbcommand(sql, conn) cmd.parameters.addwithvalue("@uoffice", voffice) cmd.parameters.addwithvalue("@udivision", vdivision) cmd.parameters.addwithvalue("@usection", vsection) cmd.parameters.addwithvalue("@uuser", vuser) seek messagebox.show("attempting update " & vuser & ". " & voffice & ", " & vdivision & ", " & vsection & "!") conn.open() cmd.executenonquery() grab ex exception messagebox.show(ex.message & vbnewline & ex.stacktrace) end seek end using end function

your sql has 2 issues:

oledbcommands utilize question marks ? placeholder parameters, not @parametername (that's sqlcommands). section is reserved keyword, needs escaped: [section].

vb.net

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 -