-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.vb
More file actions
46 lines (37 loc) · 1.31 KB
/
DB.vb
File metadata and controls
46 lines (37 loc) · 1.31 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
Imports System.Data.OleDb
Module DB
Function Connect() As OleDbConnection
Dim connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "/data.mdb")
connection.Open()
Return connection
End Function
Function GetDataTable(sql As String) As DataTable
Dim connection = Connect()
Dim dataTable As New DataTable()
Using cmd As New OleDbCommand(sql, connection), adapter As New OleDbDataAdapter(cmd)
cmd.Connection.Close()
adapter.Fill(dataTable)
End Using
connection.Close()
Return dataTable
End Function
Function ExecuteNonQuery(sql As String) As Boolean
Using cmd As New OleDbCommand With {
.Connection = Connect(),
.CommandText = sql
}
Dim isSuccess = False
Try
cmd.ExecuteNonQuery()
isSuccess = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cmd.Connection.Close()
Return isSuccess
End Using
End Function
Function RowsCount(sql As String) As Integer
Return GetDataTable(sql).Rows.Count()
End Function
End Module