VB.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  Update cell data in an Excel file using OLEDB

Without using Excel Object we can insert , edit , delete , select etc. in cell content of an Excel 2007 file using OLEDB in VB.NET 2005 . Here we are using OleDbConnection , OleDbDataAdapter , DataSet for doing these operations in an Excel file. You have to import System.Data in the project for doing these operations . For update the content in the cell or modify the content in a cell , We can use the UPDATE command like in SQL Operations.

sample UPDATE sql

sql = "Update [Sheet1$] set name = 'New Name' where id=1"

The follwoing picture shows before and after update of the Sheet.

vb.net_excel_update_oledb.JPG
         VB.NET Source Code Download           Print Source Code
         Update cell data in an Excel file using OLEDB - Download
        
C# Tutorial

Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim myCommand As New System.Data.OleDb.OleDbCommand
            Dim sql As String

            MyConnection = New System.Data.OleDb.OleDbConnection _
            ("provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + _
            "'c:\testfile.xls';Extended Properties=Excel 8.0;")

            MyConnection.Open()
            myCommand.Connection = MyConnection
            sql = "Update [Sheet1$] set name = 'New Name' where id=1"
            myCommand.CommandText = sql
            myCommand.ExecuteNonQuery()
            MyConnection.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        MsgBox("Updated ")
    End Sub
End Class

When you execute this source code the will update the corrosponding content.

VB.NET 2005 Excel 2007 Related Contents
*     How to create an Excel 2007 file in VB.NET 2005
*     How to open or read an existing Excel 2007 file in VB.NET 2005
*     How to read entire worksheet in an Excel workbook
*     How to Format Excel 2007 Page in VB.NET
*     How to insert a Picture in Excel 2007 through programing on VB.NET 2005
*     How to insert a background Picture in Excel 2007 through VB.NET 2005
*     How to create a Chart in Excel 2007 in VB.NET
*     How to export a Chart in Excel 2007 as Picture file from VB.NET
*     How to Excel 2007 Chart in VB.NET Picture Box
*     How to Excel 2007 DataBar in VB.NET
*     How to Excel 2007 Data Validation Input Message
*     How to read data from excel using OLEDB
*     How to insert cell data in an Excel file using OLEDB
*     How to export from database to excel
*     How to export from DataGridView to excel


   Home      VB.NET      C#
VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
*     VB.NET DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.