-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMSAccessConnection.vb
More file actions
55 lines (28 loc) · 1.14 KB
/
Copy pathMSAccessConnection.vb
File metadata and controls
55 lines (28 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Public Class MSAccessConnection
Dim _dbFilePath As String
Public Sub New(dbFilePath As String)
_dbFilePath = dbFilePath
End Sub
Public Function QueryIntoDataTable(sql As String) As DataTable
Using cnn As New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _dbFilePath & ";Persist Security Info=False;"
Using cmd As New OleDb.OleDbCommand(sql, cnn)
Using da As New OleDb.OleDbDataAdapter(cmd)
Using dt As New DataTable
da.Fill(dt)
Return dt
End Using
End Using
End Using
End Using
End Function
Public Sub ExecuteSql(sql As String)
Using cnn As New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _dbFilePath & ";Persist Security Info=False;"
cnn.Open()
Using cmd As New OleDb.OleDbCommand(sql, cnn)
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Class