-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMysql.vb
More file actions
103 lines (84 loc) · 3.37 KB
/
Mysql.vb
File metadata and controls
103 lines (84 loc) · 3.37 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Imports MySql.Data.MySqlClient
Module Mysql
Public conn As New MySqlConnection
Public cmd As New MySqlCommand
Public dadapter As New MySqlDataAdapter
Public datardr As MySqlDataReader
Public strSql As String
Public Sub Connection()
conn.ConnectionString = "server=127.0.0.1;user id=admin;password=admin;database=test"
conn.Open()
End Sub
Public Function Insertdata(ByVal TagId As String, Time As String, date2 As String, check As String) As Boolean
Connection()
Using cmd As New MySqlCommand()
Try
strSql = "INSERT INTO " & TagId & " (`RFID`,`Time`,`Date`,`Check In/Out`) values (@TagID, @Time, @Date, @Check)"
cmd.CommandText = strSql
cmd.Connection = conn
dadapter.SelectCommand = cmd
With cmd
.CommandType = CommandType.Text
.Parameters.AddWithValue("@TagID", TagId)
.Parameters.AddWithValue("@Time", Time)
.Parameters.AddWithValue("@Date", date2)
.Parameters.AddWithValue("@Check", check)
End With
cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
End Try
End Using
Return Nothing
End Function
Public Function EditData(status As String) As Boolean
Dim iReturn As Boolean
Using SQLConnection As New MySqlConnection("server=127.0.0.1;user id=admin;password=admin;database=test")
Using sqlCommand As New MySqlCommand()
With sqlCommand
.CommandText = "UPDATE workers SET status = '" & status & "' WHERE RFID='" & Form1.txtTag.Text & "' ;"
.Connection = SQLConnection
.CommandType = CommandType.Text
End With
SQLConnection.Open()
sqlCommand.ExecuteNonQuery()
iReturn = True
End Using
End Using
Return iReturn
End Function
'Public Function Online() As Boolean
' Dim iReturn As Boolean
' Using SQLConnection As New MySqlConnection("server=127.0.0.1;user id=admin;password=admin;database=test")
' Using sqlCommand As New MySqlCommand()
' With sqlCommand
' .CommandText = "UPDATE workers SET status = ' ' WHERE RFID='" & Form1.txtTag.Text & "' ;"
' .Connection = SQLConnection
' .CommandType = CommandType.Text
' End With
' SQLConnection.Open()
' sqlCommand.ExecuteNonQuery()
' iReturn = True
' End Using
' End Using
' Return iReturn
'End Function
Public Function Mysql(command As String) As String
Call Connection()
Dim x As String
Try
strSql = command
cmd.CommandText = strSql
cmd.Connection = conn
dadapter.SelectCommand = cmd
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
x = datardr("Name")
End If
Catch ex As Exception
End Try
conn.Close()
Return x
End Function
End Module