473,387 Members | 1,611 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,387 software developers and data experts.

Excel to VB.net to Access HELP!!

HELLO world, this is my first post and heres my problem.

I have an excel spreadsheet with 22 columns, and undefined amount of rows. I need vb.net to read the data from excel. Then use that data to populate an existing access database table that has been added to visual studio. I've tried multiple approaches and have come to a standstill.

this was approach 1

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2. Imports System.Data.SqlClient
  3. Imports Excel = Microsoft.Office.Interop.Excel
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportFile.Click
  6.         'Open File Dialog to Find the file.
  7.         FD.InitialDirectory = "C:\"
  8.         FD.Title = "Choose an Excel File to load"
  9.         FD.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*"
  10.         FD.ShowDialog()
  11.         'Open File
  12.         FD.OpenFile()
  13.  
  14.         'Read Excel Filei
  15.         Dim xlApp As Excel.Application
  16.         Dim xlWB As Excel.Workbook
  17.         Dim xlSheet As Excel.Worksheet
  18.  
  19.  
  20.         Dim range As Excel.Range
  21.         Dim intRowCount As Integer
  22.         Dim intColumnCount As Integer
  23.  
  24. Dim taMeasurement As New FOSRLab3DataSetTableAdapters.Sample_MeasurementsTableAdapter
  25.         xlApp = New Excel.ApplicationClass
  26.         xlWB = xlApp.Workbooks.Open(FD.FileName)
  27.         xlSheet = xlWB.Worksheets(1)
  28.         range = xlSheet.UsedRange
  29.         Dim ta As New FOSRLab3DataSetTableAdapters.Sample_MeasurementsTableAdapter
  30.  
  31.  
  32.  
  33.         For intRowCount = 2 To range.Rows.Count
  34.         SiteID = CType(range.Cells(intRowCount, 1), Excel.Range)
  35.         drSiteID.SiteName = SiteID.ToString
  36.         Next
  37.       xlWB.Close()
  38.         xlApp.Quit()
  39.         releaseObject(xlApp)
  40.         releaseObject(xlWB)
  41.         releaseObject(xlSheet)
  42.  
  43.  
  44.     End Sub
  45.  
Heres another failed approach
Expand|Select|Wrap|Line Numbers
  1. 'For Each row As Microsoft.Office.Interop.Excel.Worksheet
  2.     'xlSheet.Cells(1, 1) = "SiteName"
  3.     'Next
  4.     'MsgBox(xlSheet.Cells(1, 1).ToString)
  5.  
  6.  
  7.  
  8.     'Try
  9.     'Dim MyConnection As System.Data.OleDb.OleDbConnection
  10.     'Dim DtSet As System.Data.DataSet
  11.     '     Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
  12.     '    MyConnection = New System.Data.OleDb.OleDbConnection("provider = Microsoft.Jet.OLEDB.4.0;"" Data Source = FD.FileName';""Extended Properties = Excel 8.0;")
  13.     '   MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT * from [Site Data]", MyConnection)
  14.     '  MyCommand.TableMappings.Add("Table", "TestTable")
  15.     ' DtSet = New System.Data.DataSet
  16.     'MyCommand.Fill(DtSet)
  17.     'DataGridView1.DataSource = DtSet.Tables(0)
  18.     'MyConnection.Close()
  19.     'Catch ex As Exception
  20.     'MsgBox(ex.ToString)
  21.     'End Try
  22.  
Oct 20 '08 #1
1 1461
joedeene
583 512MB
Would this help maybe? If not, have you tried Google?

joedeene
Oct 20 '08 #2

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

Similar topics

0
by: MARK TURNER | last post by:
Hi, Can anyone point me in the right direction to learn how to get real time updates in an Access form from an Excel spreadsheet? I'm trying to link the following formula which exists in an...
3
by: news.giganews.com | last post by:
Does anyone know if there's an easy way to export or copy the relationship structure from one mdb to a new one? The relationships in the db are time consuming to reproduce. I am trying to make a...
1
by: kelvinweb | last post by:
Hi All, How to using asp script update data in Excel Spreadsheet with style (ie, Bold, Font Size ..) ? Is it possible to do that ?
1
miffe
by: miffe | last post by:
Greetings, I've got an access database on a server, and in a client PC I've got an excel spreadsheet... I run a query from the client PC involving some maths to develop different price lists from...
7
by: farhaaad | last post by:
Hi everybody, I just wanted to know if i can make a form in excel (the same as access forms), so when i enter data in excel form it goes to a table in access ? I mean when i enter a value in a...
4
by: DyingIsis | last post by:
Hello - I'm a relatively new user of Access. None the less, I have a function within Excel that I would like to recreate in Access. The function called (Check if part of a cell matches...
3
by: pochimen | last post by:
Hi everyone, i`m trying to make access interact with excel in vba I have an excel sheet with 3 columns and 30 rows, and an access table of 4000 rows. The idea is to compare every row of the...
2
risk32
by: risk32 | last post by:
OK. So I have NO idea what I'm doing. I've only worked with Excel VBA, JS, and HTML. No clue how to use access since it's different (except maybe the VB portion of Excel VBA). I'm trying to make a...
0
by: TrevoriousD | last post by:
hi I have created a data link from access query to excel. I use excel pull data from access in order to do stats. the excel workbook always stays in the same folder as the access db. I want to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...

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.