473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET : Excel To Access through ADOX

3 New Member
Hi,

I'm a bit confused with all the types of connections (odbc, oledb, adox, etc...)

I'm making an application which imports the data from an excel file to a table into MS Access.

I decided to connect directly the excel file with a linked Access table (through adox), and make all my queries to the database. No need to store the data in a datatable or such!

The problem is that I don't know how to delete those tables after the user exits the application. Of course, I need to delete those tables to avoid my database growing every executions of the application...

here's the interesting part of this app :

Expand|Select|Wrap|Line Numbers
  1.     Sub AttachXLStoDB(ByVal ExcelPath As String, ByVal sheetName As String)
  2.  
  3.         Dim ADOXTable As New ADOX.Table
  4.         Dim ADOXCatalog As New ADOX.Catalog
  5.         Dim ADOConnection As New ADODB.Connection
  6.  
  7.         'Delete de first and last square bracket character in worksheet name (eg. [Sheet1$] -> Sheet1$
  8.         If (sheetName.EndsWith("]")) Then
  9.             sheetName = sheetName.Remove(sheetName.Length - 1, 1)
  10.             sheetName = sheetName.Remove(0, 1)
  11.         End If
  12.  
  13.  
  14.         Try
  15.             'link an access table to the excel country menu file
  16.             ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
  17.             "Data Source=C:\Documents and Settings\Administrator\My Documents\Projets\foo.mdb;" & _
  18.             "Jet OLEDB:Engine Type=4;")
  19.  
  20.             ADOXCatalog.ActiveConnection = ADOConnection
  21.  
  22.             ADOXTable.ParentCatalog = ADOXCatalog
  23.             ADOXTable.Name = sheetName
  24.             ADOXTable.Properties("Jet OLEDB:Remote Table Name").Value = sheetName
  25.             ADOXTable.Properties("Jet OLEDB:Link Provider String").Value = "Excel 8.0;DATABASE=" & ExcelPath & ";HDR=YES"
  26.  
  27.             ADOXTable.Properties("Jet OLEDB:Create Link").Value = True
  28.             ADOXCatalog.Tables.Append(ADOXTable)
  29.  
  30.  
  31.         Catch ex As Exception
  32.             MessageBox.Show(ex.Message)
  33.         Finally
  34.             ADOConnection.Close()
  35.         End Try
  36.  
  37.     End Sub
  38.  
I need to delete those after the applications stops, so I can't use a ADOXCatalog.tab les.Delete(xxxx )...

Thanks for your help ;)
Apr 3 '07 #1
2 2634
mazelx
3 New Member
no idea???????????
Apr 6 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Welcome to the site. You may be able to use thread management. However, it may be easier to delete tables each time the application is started. HTH.
Apr 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7277
by: JBAdamsJr | last post by:
I want to be able to create an Excel file with a VB.NET program on a server that does not have Microsoft Excel loaded on it. I am using the Jet OLE DB to read other data files. Can this be used to save an array in an Excel .XLS format?
4
846
by: Paxton | last post by:
I can connect to an Excel worksheet and get records with no problem, if I know the worksheet's name. However, when my users upload their excel files, I don't know what the active sheet they want to work from is called. I have two options - either force them all to give the saem name to every worksheet they upload, or providing them with an input field where they can provide the name of the relevant worksheet Rather than force my...
41
6100
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there is one row containing picture(s) as well. So far, what I did is doing it manually for each word docs I have. Select Table Convert Table to Text(I use ^ character for delimiter)
12
3569
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new field with the type AutoNumber. I can then set this up as a key. Then if I go into the table I will see sequential numbers have been inserted into that field for me. Can I do this through VB.net I'd appreciate any help or alternative suggestions...
6
6366
by: syvman | last post by:
Hi everyone... I am pulling my hair out trying to do this, and was wondering if someone could give me some assistance... I have an Excel spreadsheet containing several worksheets. I'd like to be able to take all of the data from the second column (B) of each worksheet and append that raw data to an access table. The columns in the spreadsheet do not have headers for use as field names (it's my assumption that my table should have a...
5
6240
by: magix | last post by:
Hi, If I have following code to read the excel file, how do I validate the worksheets name ? In code below, if the filename doesn't contains "SomeName" worksheet, I will need to prompt error. set oConn = server.createobject("adodb.connection") oConn.Provider = "Microsoft.Jet.OLEDB.4.0"
0
767
by: DrewYK | last post by:
I have the project that may never end in front of me. I am creating a routine that will take SpreadSheets from Excel and bring them into Access. I am not using any "DoCmd"s because the goal is for the import code to be moved to a stand alone VB app which will use the Access DB as a workspace to process the data from the spreadsheets. Quite honestly, done right this may not even require Access or Excel to be on the users machine. ...
4
2979
by: laurasesma18 | last post by:
I've got a convertion tool with Access 2003. It imports an excel sheet into the data base and with the records in it creats different outputfiles. Its programmed with VBA. Now what I need is, in some cases, to change the excel sheet that we import. How should I do that? If anyone can give me an advise it would be great. Thank you.
2
2257
by: KC-Mass | last post by:
Is it possible to read the spreadsheet names in an Excel workbook with VBA and no Excel?
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.