473,770 Members | 5,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel to VB.net to Access HELP!!

3 New Member
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 1481
joedeene
583 Contributor
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
1448
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 Excel spreadsheet and works perfectly to an Access form. It's just like a checkbook register. C2=(C1-A2+B2)
3
7461
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 copy of a database including all the relationships, forms, queries and modules while still within the original database. This has to be a relatively automated process (button click). Any suggestions?
1
1711
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
1498
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 values stored in the DB on the server... Problem #1: I dont want the client PC to be able to control the queries, is there a way to store the access query on the server PC and have the excel worksheet just access it on the server each time? ...
7
6045
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 cell linked to access table, it goes to table and when i enter another value in the same cell the value goes to the next record. I thank you people in advance!
4
2049
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 specific text) in Excel is below: =IF(ISNUMBER(SEARCH("v",A2)),"OK", "Not OK") I have been trying to replicate it in Access with little luck.
3
1686
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 excel from only one column with every row of my access table from only one column of the same type. For examle: My excel has 3 columns: Code, Name, City. My access table has 4 columns: Code, Name, City, Country.
2
1357
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 login form with the standard txtUser txtPassword lblUser lbl Password, a reset button a cancel button and a login button. This part, pretty easy, Now, need the Visual Basic portion of it to reflect the Access portion of it. I honestly have no...
0
1956
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 able to copy the folder from one pc to another and keep the data connection from access to excel within the same folder. I looked for way to do this in the ODC file but aren't having any luck. In the Connecting string(in excel data connection) it...
0
9591
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
9425
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
10053
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...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
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...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.