473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Import Excel into Access

Hi guys

I have an excel table which I want to import into access, but I have no office installed in my PC, I have opened my database in sub main(), and then I use this code in Import_IOlist button to do the import but it didn't work

However, what I want to do is to import one sheet [IO_List] from excel file into my existing database and put the imported sheet into a new table inside my database, any help will be much appreciated.

Thank you in advance for your help

Expand|Select|Wrap|Line Numbers
  1. Private Sub Import_IOlist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Import_IOlist.Click
  2.  
  3.         Dim ExcelName, ExcelDataSource, ExcelExtension As String
  4.         Dim cmd As OleDbCommand
  5.         Dim cmd1 As OleDbCommand
  6.         Dim ExcelConn As OleDbConnection
  7.         Dim ds1 As DataSet
  8.         Dim da As OleDbDataAdapter
  9.  
  10.         da = New OleDbDataAdapter()
  11.         cmd = New OleDbCommand()
  12.         cmd1 = New OleDbCommand()
  13.         ds1 = New DataSet
  14.  
  15.         'Get the Excel file name and the extension
  16.         OpenFileDialog1.ShowDialog()
  17.         ExcelName = OpenFileDialog1.FileName
  18.         ExcelExtension = IO.Path.GetExtension(ExcelName)
  19.  
  20.         'Check if the file is Excel 2007 version, or earlier version
  21.         If ExcelExtension = ".xls" Then
  22.             ExcelDataSource = "data source=" & ExcelName & ";" & "Extended Properties=Excel 8.0;"
  23.             ExcelConn = New OleDbConnection(ProviderExcel8 & ExcelDataSource)
  24.             ExcelConn.Open()
  25.         ElseIf ExcelExtension = ".xlsx" Then
  26.             ExcelDataSource = "data source=" & ExcelName & ";" & "Extended Properties=Excel 12.0;"
  27.             ExcelConn = New OleDbConnection(ProviderExcel12 & ExcelDataSource)
  28.             ExcelConn.Open()
  29.         End If
  30.  
  31.  
  32.         'Codes to Import the data from Excel and put it into the MS Access
  33.         cmd1 = ExcelConn.CreateCommand
  34.         cmd1.Connection = ExcelConn
  35.         cmd1.CommandText = "select * into [ms access;Database= C:\Users\NOAMHUS\Documents\Amjad ABB\Engineering Tool\CBM Generator r3.2\CBM_Generator1.mdb].[NewTable] from [IO_List$]"
  36.         cmd1.ExecuteNonQuery()
  37.  
  38.  
  39.         ' Code to Import the data to data adapter, which then can be used to display the data in the DataGridView
  40.         cmd = ExcelConn.CreateCommand
  41.         cmd.Connection = ExcelConn
  42.         cmd.CommandText = "select * from [IO_List$]"
  43.         da.SelectCommand = cmd
  44.  
  45.  
  46.         Try
  47.             da.Fill(ds1, "MyTable")
  48.             MsgBox("The Import is completed!")
  49.             Me.DataGridView1.DataSource = ds1
  50.             Me.DataGridView1.DataMember = "MyTable"
  51.         Catch e1 As Exception
  52.             MsgBox("Import faield, correct Column name in the sheet!")
  53.         End Try
  54.         ExcelConn.Close()
  55.     End Sub
  56.  
Jul 18 '12 #1
1 9403
genek
3
Open your Excel Spreadsheet, select the data you want in Access and copy it into an Excel spreadsheet all by its self. Save the file as a .csv (comma seperted vocabulary) and you should be able to open the .csv file directly in Access. Set the file type to Text Files (it contains the .csv option) when you are in the Open file dialog box.
Sep 4 '12 #2

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

Similar topics

4
by: Jarod | last post by:
Hey How to import excel to my application ? I need access to all fileds in spreadsheets just to take data. Excel file works as a "dictionary" in my case. Can you tell me how to use it in...
1
by: Reggae | last post by:
Hello, I am looking for the most efficient way to programmatically batch import excel files into MS Access. The excel files are not lined up in a row and currently I am going to each file so I...
7
nehashri
by: nehashri | last post by:
hello i have my data stored in different Ms Excell sheets. now I am planning to make a database of the data i have. but i m confused whether to use Postgresql or mySQL for the same. i had plans to...
3
by: vj83 | last post by:
Hi, I have a C#.net application in which i have read the datas from excel sheet and displayed in a datagrid in my Aspx form. The code is here private void Button2_Click(object sender,...
2
by: solargovind | last post by:
Hi, Can anybody suggest me how to take data from an Excel file without import into Access as a Table..? Bcoz...I hve several file. if i import, it would take more time and increase the file...
2
by: Dave Williams | last post by:
Im not a techie but run a small business in UK. We take instructions from clients from emails hard copy, spreadsheets etc and put them on excel templates then import to Access. A client wants us to...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
8
by: qfchen | last post by:
Hi, A piece of simple code to import excel file to a database, as shown below, I have problem when I tried to open the connection, the error message shows Excel driver is not correct. where shall...
1
by: jollyroger | last post by:
I have searched the web forums, and can't seem to find an answer to this particular problem I have. In an excel sheet, cells in one column have formatted text in the "wrapped" cells. For many of...
4
by: dowlingm815 | last post by:
I am importing an Excel 97-2003 file into Access 2003. The number of rows within the Excel file is 101,9992. When completed the Access import, only 65,535 are import. Is Access limited, if so,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.