Documente Academic
Documente Profesional
Documente Cultură
NET to MySQL
End Module
DATABASE SERVER LOGIN:
Form1.vb (Design)
TextBox1
TextBox2
TextBox3
Form1.vb
Code for Connect button:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
objConn.ConnectionString = "Server=" & TextBox1.Text & "; User ID=" & TextBox2.Text & ";Password=" &
TextBox3.Text & ";Database=bsit2f"
Try
objConn.Open()
MsgBox("Connected")
Me.Hide()
Form2.Show()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
TextBox1
TextBox2
Form2.vb
Code for Login button:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
strSQL = "SELECT * FROM uaccount WHERE userName='" & TextBox1.Text & "' AND userPass='" &
TextBox2.Text & "'"
objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objDR = objCmd.ExecuteReader
If (objDR.Read()) Then
MsgBox("Welcome")
objCmd.Dispose()
objDR.Close()
TextBox1.Text = ""
TextBox2.Text = ""
Me.Hide()
Form3.Show()
Else
MsgBox("Invalid Username or Password")
End If
objCmd.Dispose()
objDR.Close()
End Sub
Form3.vb (Design)
TextBox5
TextBox1
TextBox2
TextBox3
TextBox4
ListView1
Form3.vb
Create a function for populating records in Listview:
TextBox4.Text = ""
Me.fillListview()
End Sub
Code for Delete button:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
strSQL = "DELETE FROM student WHERE studNo='" & TextBox1.Text & "'"
objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objCmd.Dispose()
MsgBox("RECORD SUCCESSFULLY DELETED", MsgBoxStyle.Information, "DELETE RECORD")
TextBox1.Text
TextBox2.Text
TextBox3.Text
TextBox4.Text
=
=
=
=
""
""
""
""
Me.fillListview()
End Sub
Code for Search:
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
Try
ListView1.Items.Clear()
strSQL = "SELECT * FROM student WHERE studName LIKE '" & TextBox5.Text & "%'"
objCmd = New MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn)
objDR = objCmd.ExecuteReader
While (objDR.Read())
With ListView1.Items.Add(objDR("studNo"))
.subitems.add(objDR("studName"))
.subitems.add(objDR("studLocation"))
.subitems.add(objDR("studAge"))
End With
End While
objCmd.Dispose()
objDR.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Code for Clear button:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Code for Exit button:
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
End
End Sub
Code for Logout button:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Me.Hide()
Form2.Show()
End Sub