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$]"
    End If
End Sub

End Class

Saving data from excel file to database will require a proper connection string to your database. Then on the button click you should add the code that will do the insert. Kindly check this tutorial which doest the exact thing - How to Import Excel File into Database in ASP.NET MVC

I hope it helps you.
Happy coding !

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.