Hello to all.
I am developing software in vb.net for sales invoices. Where i need to import invoice data from excel file to vb.net Grid Data View and then save into access db. I will use db data in future for creating customer invoices. I have code that import excel data into GDV successfully, but i d'nt know how to save data in access db. Access db Name "MyInvoice" and table Name is 'InvoiceData'. Please help me to write correct code.
Thank You.
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class MainForm
Private Sub BtnImpExcelFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnImpExcelFile.Click
Dim conn As OleDbConnection
Dim dta As OleDbDataAdapter
Dim dts As DataSet
Dim excel As String
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "All Files (*.*)|*.*|Excel files (*.xlsx)|*.xlsx|CSV Files (*.csv)|*.csv|XLS Files (*.xls)|*xls"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim fi As New FileInfo(OpenFileDialog.FileName)
Dim FileName As String = OpenFileDialog.FileName
excel = fi.FullName
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excel + ";Extended Properties=Excel 12.0;")
dta = New OleDbDataAdapter("Select * From [Sheet1$]", conn)
dts = New DataSet
dta.Fill(dts, "[Sheet1$]")
DGVImpData.DataSource = dts
DGVImpData.DataMember = "[Sheet1$]"
conn.Close()
End If
End Sub
End Class