vb.net - How to import the data from excel to the .mdb access file? -
here m have problem export data in excel
format of .mdb
. m trying code showing below, shows messagebox
import failed, correct column name in sheet!
error message:
the 'microsoft.jet.oledb.4.0' provider not registered on local machine
is there can me.
best regards, thanes
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click ' delete file same , create new access file if file.exists("c:\users\admin\desktop\test\ca\book.mdb") file.delete("c:\users\admin\desktop\test\ca\book.mdb") end if dim _accessdata access.application _accessdata = new access.application() _accessdata.visible = false _accessdata.newcurrentdatabase("c:\users\admin\desktop\test\ca\book.mdb", access.acnewdatabaseformat.acnewdatabaseformataccess2000, , , ) _accessdata.closecurrentdatabase() _accessdata.quit(microsoft.office.interop.access.acquitoption.acquitsaveall) _accessdata = nothing ' initialize connect string dim _filename string = "c:\users\admin\desktop\test\ca\test.xls" dim _conn string _conn = "provider=microsoft.jet.oledb.4.0;" & "data source=c:\users\admin\desktop\test\ca\test.xls" & _filename & ";" & "extended properties=""excel 8.0;hdr=yes;imex=1"";" dim _connection oledbconnection = new oledbconnection(_conn) 'use oledbcommand object select data sheet1 , execute executenonquery import data book.mdb. dim _command oledbcommand = new oledbcommand() _command.connection = _connection try _command.commandtext = "select * [ms access;database=c:\users\admin\desktop\test\ca\book.mdb].[sheet1] [sheet1$a4:d]" _connection.open() _command.executenonquery() _connection.close() messagebox.show("the import complete!") catch e1 exception messagebox.show("import failed, correct column name in sheet!" & environment.newline & "error message:" & environment.newline & e1.message) end try end sub
*note: program can create .mdb file, cannot import excel data it.
i m settle rdy...thank anyway help...
public class form1 private dbpath string private conn oledbconnection public sub new() initializecomponent() end sub private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click ''delete file same , create new access file if file.exists("c:\users\inari admin\desktop\test\ca\test.mdb") file.delete("c:\users\inari admin\desktop\test\ca\test.mdb") end if dbpath = "c:\users\inari admin\desktop\test\ca\test.mdb" ' create db via adox if not exists ' note: use adox add reference com microsoft ado ext. 2.6 ddl , security! if not file.exists(dbpath) dim cat new adox.catalog() cat.create(convert.tostring("provider=microsoft.jet.oledb.4.0;data source=") & dbpath) cat = nothing end if conn = new oledbconnection(convert.tostring("provider=microsoft.jet.oledb.4.0;data source=") & dbpath) conn.open() try using cmd new oledbcommand("create table [test] ([id] counter primary key, [num] int, [name] memo, [no] int);", conn) cmd.executenonquery() end using catch ex exception if ex isnot nothing ex = nothing end if end try ' initialize connect string dim _filename string = "c:\users\inari admin\desktop\test\ca\test.xls" dim _conn string = "provider=microsoft.jet.oledb.4.0;" & "data source=" & _filename & ";" & "extended properties=""excel 8.0;hdr=yes;imex=1"";" dim _connection oledbconnection = new oledbconnection(_conn) 'use oledbcommand object select data sheet1 , execute executenonquery import data test.mdb. dim _command oledbcommand = new oledbcommand() _command.connection = _connection try using conn new oledbconnection(_conn) using cmd new oledbcommand() cmd.connection = conn cmd.commandtext = "insert [ms access;database=" + dbpath + "].[test] select * [sheet1$]" conn.open() cmd.executenonquery() end using end using '_command.commandtext = "select * [sheet1$]" '_connection.open() '_command.executenonquery() '_connection.close() messagebox.show("the import complete!") catch e1 exception messagebox.show("import failed, correct column name in sheet!" & environment.newline & "error message:" & environment.newline & e1.message) end try end sub end class
Comments
Post a Comment