Imports DemoExcelFileHandling.DataSet1
Imports DemoExcelFileHandling.DataSet1TableAdapters

Public Class ReadFromExcel
Private dt As New dtMonthDataTable
Private ta As New taMonth
Private bs As New BindingSource

Private Sub BindUI()
dgvExcelData.AutoGenerateColumns = False
colYear.DataPropertyName = "Year1"
colMonth.DataPropertyName = "Month1"
colFacility.DataPropertyName = "Facility"
colProductCode.DataPropertyName = "ProductCode"
colProductDesc.DataPropertyName = "ProductDesc"
colUnit.DataPropertyName = "UnitOfIssue"
colBegBalance.DataPropertyName = "Beginning_Balance"
colQtyReceived.DataPropertyName = "QuantityReceived"
colQtyDispensed.DataPropertyName = "QuantityDispensed"
colLosses.DataPropertyName = "Losses "
colAdjustments.DataPropertyName = "Adjusments"
colEndingBal.DataPropertyName = "Ending_Balance_Book"
colEndingBalPhysical.DataPropertyName = "Ending_Balance_Physical"
ColQtyLeft.DataPropertyName = "3_months_shelflife"
colQtyRequired.DataPropertyName = "Quantity_Ordered"

End Sub

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
If ofdOpenFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
txtFileName.Text = ofdOpenFile.FileName
End If
End Sub

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
If Not String.IsNullOrEmpty(txtFileName.Text) Then
Try
btnClose.Enabled = False
Dim OExcelHandler As New ExcelHandler()
Dim ds As DataSet = OExcelHandler.GetDataFromExcel(txtFileName.Text.Trim())

If ds IsNot Nothing Then
dgvExcelData.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dgvExcelData.EditMode = DataGridViewEditMode.EditProgrammatically
dgvExcelData.DataSource = ds.Tables(0)
End If

Catch ex As Exception

Finally
btnClose.Enabled = True
End Try
End If
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
bs.EndEdit()
ta.Update(dt)
End Sub

Private Sub ReadFromExcel_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindUI()
End Sub
End Class

Hi,

Looking at your code, you are referencing a class OExcelHandler to populate your dataset, with out knowing what happens in the class I can't help.

If it uses a dataadaptor, you could be able to specify the Update command if it is accessible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.