473,507 Members | 6,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve Data from Excel to fill DataGridView

126 New Member
Hi Friends,
I need your help. Please help me.

I am trying to retrieve data from Excel Spreadsheet to fill the DataGridView for display prior to updating SQL SERVER with individual DataGridView row and encounter this error message: Public member 'WorkbookOpen' on type 'ApplicationClass' not found. which is caused by this coding trying to open the Excel WorkBook with the Excel name and Folder path.

Dim objBook As Excel.Workbook = CType(objExcel.WorkbookOpen(excelPathName), Excel.Workbook)

-------------------------------------------------------------------
This coding prompt user to select Excel name and folder path
Expand|Select|Wrap|Line Numbers
  1.  Private Sub btnFolderDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFolderDialog.Click
  2.         'prompt user to select Excel name and folder path
  3.         excelPathName = ""
  4.         Dim openFileDialog1 As System.Windows.Forms.OpenFileDialog
  5.         openFileDialog1 = New System.Windows.Forms.OpenFileDialog
  6.  
  7.         With OpenFileDialog1
  8.             .Title = "Excel Spreadsheet"
  9.             .FileName = ""
  10.             .DefaultExt = ".xls"
  11.             .AddExtension = True
  12.             .Filter = "Excel  (*.xls)| *.xls|All File(*.xls)|.xls"
  13.  
  14.             If .ShowDialog = Windows.Forms.DialogResult.OK Then
  15.                 excelPathName = (CType(.FileName, String))             
  16.                 End If
  17.             End If
  18.         End With
  19.  
  20.     End Sub 
----------------------------------------------------------------------
This coding retrieve data from Excel to fill DataGridView and error generated here
Expand|Select|Wrap|Line Numbers
  1.   Private Sub btnOpenExcel_Click(ByVal sender As System.Object,
  2.      ByVal e As System.EventArgs) Handles btnOpenExcel.Click
  3.  
  4.         Dim objExcel As Excel.Application = CType(CreateObject("Excel.Application"), Excel.Application)
  5.         Dim objBook As Excel.Workbook = CType(objExcel.WorkbookOpen(excelPathName))  <---- cause Error messsage ******* 
  6.         Dim objSheet As Excel.Worksheet = CType(objExcel.Worksheets(1), Excel.Worksheet)
  7.         objSheet.Visible = True
  8.  
  9.         Dim bolFlag As Boolean = True
  10.         Dim excelRow = 6
  11.         Dim excelCol = 1
  12.         Dim DGVRow = 0
  13.  
  14.     Try
  15.        Do While bolFlag = True
  16.  
  17.        With DataGridView1
  18.           .Rows.Add()
  19.           DGVRow += 1
  20.           excelRow += 1
  21.  
  22.            If objSheet.Cells(excelRow, 0) = "" Then
  23.                bolFlag = False
  24.                Exit Do
  25.            End If
  26.  
  27.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 0) 
  28.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 1)  
  29.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 2) 
  30.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 3)  
  31.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 4)  
  32.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 5)  
  33.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 6)  
  34.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 7) 
  35.           .Rows(DGVRow).Cells(0).Value = objSheet.Cells(excelRow, 8)  
  36.  
  37.       End With
  38.      Loop
  39.  
  40.  Catch ex As Exception
  41.          MessageBox.Show(ex.Message)
  42.  
  43.  Finally
  44.      objBook.Close()
  45.      objExcel.Quit()
  46. End Try
  47.     End Sub
Thank you for your help

Have a Good Day.
Cheers,
Lennie
May 26 '10 #1
0 1615

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

Similar topics

4
3921
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
2
1294
by: Rachel | last post by:
Hi All: I would like to know how to prevent a dataset from being filled with garbage data. Forinstance, if I am importing data from an excel spreadsheet into a dataadapter and the first...
1
3241
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
7
2878
by: Greg P | last post by:
I'm new to VS2005 and want to simply update my data with the dataGridView that was generated when I draged my query from the Data Sources Pane. I think I may need to create a Data Adaptor but I'm...
8
7187
by: Yoshitha | last post by:
Hi I want to Extracet(retrieve) data from some of websites and the retrieved data has to be saved in excel or.csv files. I need to develop this in ASP.net(using C#.net Vs 2003). Can any...
10
63073
by: pauljohns353 | last post by:
Hi, I am new to VB.net programming and was wondering if anybody has any suggestions as to how I can export data from a DataGridView via a command button to a CSV file. Any suggestions or sample...
1
6518
by: RajithaV | last post by:
Hi, I am developing a web application using ASP.Net I am using sql server.My coding is in VB.net I want to know how to move data from excel file into the Database. I also need to know how to...
4
7196
by: Anthoni | last post by:
Dear All, I need to export data of unbound datagridview to XML file. Since my DataSource is NULL, What other options do I have? Does i need to make 2 loops (on all the records and inside loop of...
9
2670
by: trint | last post by:
How can I retrieve all of the data from a datagridview? Any help is appreciated. Thanks, Trint
1
2242
by: dillipdhal | last post by:
Hi This is Dillip from HSBC Software,Hyd. Now I m working in a financial domain. Please help me in "How can I insert data from a datagridview to database in vb .net and also retrive the data "
0
7109
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...
1
7029
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...
0
7481
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...
1
5039
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
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...

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.