Deva
Member
- Joined
- Feb 10, 2021
- Messages
- 18
- Programming Experience
- 1-3
VB.NET:
Imports System.Data.OleDb
Imports System.Data.SQLite
Public Class Form1
Private Function saveData(sql As String)
Dim Sqliteconn As SQLiteConnection = New SQLiteConnection("Data Source=C:\Users\deva\source\repos\Sqlite\Sqlite\bin\Debug\Config.db;version=3;")
Dim cmd As SQLiteCommand
Dim resul As Boolean
Try
Sqliteconn.Open()
cmd = New SQLiteCommand
With cmd
.Connection = Sqliteconn
.CommandText = sql
'MsgBox(sql)
resul = .ExecuteNonQuery()
End With
Catch ex As Exception
MsgBox(ex.Message)
Finally
Sqliteconn.Close()
End Try
Return resul
End Function
Dim filename As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "All Files (*.*)|*.*| Excel |*.xlsx | Xls file |*.xls |Csv |*.csv"
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
filename = OpenFileDialog1.FileName
TextBox1.Text = filename
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim conn As OleDbConnection
Dim dat As OleDbDataAdapter
Dim dts As DataTable
Dim sql As String
Dim resul As Boolean
dat = New OleDbDataAdapter
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + ";Extended Properties=Excel 12.0;")
dat = New OleDbDataAdapter("select * from [sheet1$]", conn)
dts = New DataTable
dat.Fill(dts)
' DataGridView1.DataSource = dts
For Each r As DataRow In dts.Rows
sql = "INSERT INTO tblperson (FNAME,LNAME,ADDRESS) VALUES ('" & r(0).ToString & "','" & r(1).ToString & "','" & r(2).ToString & "')"
resul = saveData(sql)
Next
End Sub
End Class
Last edited by a moderator: