Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Import Excel Spreadsheet into DataGrid

Posted on March 25, 2013October 26, 2015 By David Kittell

Originally found at http://blueraiden.exofire.net/blog/import-excel-spreadsheet-data-to-datagridview-using-vb-net

For the code to work you need to first add a DataGridView and a Button in design view and have a valid file path for the Excel file.

Imports System.Data.SqlClient

Public Class Form1

	Dim MyConnection As System.Data.OleDb.OleDbConnection
	Dim ExcelDataSet As System.Data.DataSet
	Dim ExcelAdapter As System.Data.OleDb.OleDbDataAdapter

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:/temp/contacts.xlsx;Extended Properties=Excel 12.0;")
		Try
			ExcelAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
			ExcelAdapter.TableMappings.Add("Table", "Excel Data")
			ExcelDataSet = New System.Data.DataSet
			ExcelAdapter.Fill(ExcelDataSet)
			DataGridView1.DataSource = ExcelDataSet.Tables(0)
			MyConnection.Close()
		Catch ex As Exception
			MessageBox.Show("Error: " + ex.ToString, "Importing Excel", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End Try
End Sub
End Class
Originally Posted on March 25, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code VB.NET

Post navigation

Previous post
Next post

Related Posts

Mac OSX – Update DNS Based On WiFi

Posted on June 8, 2016June 8, 2016

I often have to bounce between WiFi at the office and the public WiFi so I finally put this script together. You will need to get the BSSID of your WiFi connection to replicate this but here is the code, of course you need to run this with sudo privileges…

Read More

WordPress Change URL – MySQL – Update String Within Column

Posted on October 17, 2014January 15, 2021

Recently I changed a domain alias for a WordPress site and needed to change the domain in all the pages/posts and this little script came in handy. Typical disclaimer stands, do a full backup before running this and verify you have everything setup correctly. UPDATE wp_options SET option_value = REPLACE(option_value,…

Read More

Gregorian Date to Hijri Date

Posted on December 3, 2013October 26, 2015

Recently I was asked to help convert Gregorian Date to Hijri Date and vice versa. One thing to note is that with Hijri date format you must keep it as a string. SELECT CONVERT(varchar(30), GETDATE(), 131) — Returns: 30/01/1435 8:33:10:030AM SELECT CONVERT(datetime, ’30/01/1435 8:32:19:467AM’, 131) — Returns: 2013-12-03 08:32:19.467 Originally…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes