F
Faizan R
Guest
Hello to all.
I have code that import invoice data from excel file into Datagridview in vb.net. What i tried to export this dgv data into access db. The problem is that i don't know how to write a code for exporting datagridview data into access db. My Access db Name "mydb.accdb" and table Name is 'myTable'.
Please Help me to write code for me that fulfill my requirement. I'm very thankful to all of you for help.
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
TYSM for Future Help
Continue reading...
I have code that import invoice data from excel file into Datagridview in vb.net. What i tried to export this dgv data into access db. The problem is that i don't know how to write a code for exporting datagridview data into access db. My Access db Name "mydb.accdb" and table Name is 'myTable'.
Please Help me to write code for me that fulfill my requirement. I'm very thankful to all of you for help.
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
TYSM for Future Help
Continue reading...