473,664 Members | 2,995 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 'ApplicationCla ss' 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(ex celPathName), 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 1636

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

Similar topics

4
3936
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 record from the db and then display for the user: oleDbConnection1.Open();
2
1308
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 column has data with decimal places and I do not want ANY data to go into the dataset if this condition is true, instead I want to have a message box appear telling the user what is wrong. How should I code this? I will do the same sort of thing with...
1
3245
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 code fails at "objConn.Open()" with the error: System.Data.OleDb.OleDbException: Could not find installable ISAM. Can somebody please help me out? I'm still a learning programmer, so if someone can point out my mistakes, it'll be great! Thanks! ...
7
2890
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 not sure? The other think I saw was to implement IEditable? How would I do that? Where in my code woudl I do that considering I am not creating the DataGridView via code? I know this is probably the easist thing to do I just don't know how?...
8
7196
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 one tell me the idea of how to get data from websites?
10
63109
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 code would be really appreciated. Many thank. Paul.
1
6521
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 retrieve data from Database and show it in excel file. Thanks in advance for any replies. rajitha
4
7215
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 all the cells) read data and export it to XML? TIA,
9
2674
by: trint | last post by:
How can I retrieve all of the data from a datagridview? Any help is appreciated. Thanks, Trint
1
2283
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
8861
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
8778
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
8636
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
7375
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...
0
5660
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1759
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.