Repository navigation
Expand file tree
/
Copy pathmodSQL.vb
More file actions
89 lines (81 loc) · 4 KB
/
Copy pathmodSQL.vb
File metadata and controls
89 lines (81 loc) · 4 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
Imports MySql.Data.MySqlClient
Module modSQL
'Database Connection
Public Sub connect()
Try
strServer = "localhost"
strDatabaseName = "dblibrary"
strUser = "admin"
strPass = "admin"
If Not conn Is Nothing Then conn.Close()
conn = New MySqlConnection
conn.ConnectionString = String.Format("server={0}; user id={1}; " & _
"password={2}; database={3};", _
strServer, strUser, strPass, _
strDatabaseName)
conn.Open()
With frmLogin
.lblConnection.Text = "Connected"
.lblConnection.ForeColor = Color.Green
End With
Catch ex As Exception
MsgBox("Error connection: " & ex.Message, MsgBoxStyle.Critical, "Error")
With frmLogin
.lblConnection.Text = "Disconnected"
.lblConnection.ForeColor = Color.Red
End With
End Try
End Sub
'Add User
Public Sub AddUser(ByVal iUserID As TextBox, ByVal iFirstName As TextBox, ByVal iLastName As TextBox, ByVal iMiddleName As TextBox, ByVal iAddress As TextBox, ByVal iContactNo As TextBox, ByVal iEmail As TextBox, ByVal iUsername As TextBox, ByVal iPassword As TextBox, ByVal iRole As ComboBox)
strAddUserQuery = "INSERT INTO dblibrary.tblusers(UserID, FirstName, LastName, " & _
"MiddleName, Address, ContactNo, EmailAdd, username, password, role) " & _
"VALUES(@iUserID, @iFirstName, @iLastName, @iMiddleName, @iAddress, " & _
"@iContactNo, @iEmail, @iUsername, @iPassword, @iRole)"
Try
If Not conn Is Nothing Then conn.Close()
strCmd = New MySqlCommand(strAddUserQuery, conn)
strCmd.Parameters.AddWithValue("@iUserID", iUserID.Text)
strCmd.Parameters.AddWithValue("@iFirstName", iFirstName.Text)
strCmd.Parameters.AddWithValue("@iLastName", iLastName.Text)
strCmd.Parameters.AddWithValue("@iMiddleName", iMiddleName.Text)
strCmd.Parameters.AddWithValue("@iAddress", iAddress.Text)
strCmd.Parameters.AddWithValue("@iContactNo", iContactNo.Text)
strCmd.Parameters.AddWithValue("@iEmail", iEmail.Text)
strCmd.Parameters.AddWithValue("@iUsername", iUsername.Text)
strCmd.Parameters.AddWithValue("@iPassword", iPassword.Text)
strCmd.Parameters.AddWithValue("@iRole", iRole.Text)
da.SelectCommand = strCmd
dbDataSet.Clear()
da.Fill(dbDataSet)
bSource.DataSource = dbDataSet
da.Update(dbDataSet)
conn.Close()
Catch ex As Exception
MsgBox("Error Adding New User: " & ex.Message, MsgBoxStyle.Critical, "Error")
conn.Close()
End Try
End Sub
'Add Membership
Public Sub AddMembership(ByVal iUserID As TextBox, ByVal iDateJoined As String, ByVal iValidity As String)
strAddMembershipQuery = "INSERT INTO dblibrary.tblmembership(UserID, DateJoined, Validity) " & _
"VALUES(@iUserID, @iDateJoined, @iValidity)"
Try
If Not conn Is Nothing Then conn.Close()
strCmd = New MySqlCommand(strAddMembershipQuery, conn)
strCmd.Parameters.AddWithValue("@iUserID", iUserID.Text)
strCmd.Parameters.AddWithValue("@iDateJoined", iDateJoined)
strCmd.Parameters.AddWithValue("@iValidity", iValidity)
da.SelectCommand = strCmd
dbDataSet.Clear()
da.Fill(dbDataSet)
bSource.DataSource = dbDataSet
da.Update(dbDataSet)
conn.Close()
MsgBox("Record Saved!", MsgBoxStyle.Information, "Successful")
Catch ex As Exception
MsgBox("Error Adding Membership Info: " & ex.Message, MsgBoxStyle.Critical, "Error")
conn.Close()
End Try
End Sub
End Module