Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views14 pages

Vbcode11 5 24

Uploaded by

skrtskrtbrtbrt54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

Vbcode11 5 24

Uploaded by

skrtskrtbrtbrt54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

''''frmCustomer code''''''

Imports System.Text.RegularExpressions
Imports MySql.Data.MySqlClient
Public Class frmCustomer

Private EmailValid As Boolean


Private Sub frmCustomer_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
idPicture.ImageLocation = "D:\Lecture_programs\installment\InstallmentSys\
photo\default.jpg"
sDate.Text = Format(Date.Now, "MMMMMMMMM dd, yyyy")
lockObject()

End Sub

Private Sub lockObject()


btnSave.Enabled = False
txtID.Enabled = False
txtFname.Enabled = False
txtMname.Enabled = False
txtLname.Enabled = False
txtAddress.Enabled = False
txtCP.Enabled = False
txtEmail.Enabled = False
btnClear.Enabled = False
btnUpload.Enabled = False
End Sub
Private Sub clearText()
txtID.Text = ""
txtFname.Text = ""
txtLname.Text = ""
txtCP.Text = ""
txtMname.Text = ""
txtAddress.Text = ""
txtEmail.Text = ""
txtPath.Text = ""
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
newrecord = True
'clearText()
txtFname.Focus()
unlockOject()
btnAdd.Enabled = False
btnEdit.Enabled = False
btnDelete.Enabled = False
btnClear.Enabled = True
btnUpload.Enabled = True
generateID()
End Sub
Private Sub unlockOject()
txtFname.Enabled = True
txtMname.Enabled = True
txtLname.Enabled = True
txtAddress.Enabled = True
txtCP.Enabled = True
txtEmail.Enabled = True
btnSave.Enabled = True
End Sub
Private Sub generateID()
Try
Dim num As Integer
Dim idnum As String

Dim ddate As String = Date.Today.Year


num = Convert.ToInt32(getMaxNumber()) '1
idnum = "CUS-" & ddate & "-" & num 'CUS-2024-1
txtID.Text = idnum

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
If txtFname.Text = "" Or txtLname.Text = "" Or txtCP.Text = "" Or
txtPath.Text = "" Then
MsgBox("Fill-in the required customer information",
MsgBoxStyle.Critical, "ERROR!!!")
Exit Sub
Else
Try
If (MyCon.State = ConnectionState.Open) Then
MyCon.Close()
End If
MyCon.Open()
If newrecord = True Then
ExecButton("INSERT INTO tblcustomer VALUES('0','" & txtID.Text
& "','" & txtFname.Text.ToUpper() & "', '" & txtMname.Text.ToUpper() & "','" &
txtLname.Text.ToUpper() & "','" & txtAddress.Text.ToUpper() & "', '" &
txtEmail.Text & "','" & txtCP.Text & "','" & txtPath.Text & "')")

MsgBox("Records have been successfully saved.",


MsgBoxStyle.Information, "Success")

Dim terminate = MessageBox.Show("Do you want to add another


customer?", "Confirmation Message.", MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If terminate = DialogResult.Yes Then
clearText()
generateID()
txtFname.Focus()

btnAdd.PerformClick()

Else
modeObject("frmCustomer")

End If
idPicture.ImageLocation = "D:\Lecture_programs\installment\
InstallmentSys\photo\default.jpg"
Else

End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
MyCon.Close()

End Sub
Private Sub ValidateEmail()

'Set Up Reg Exp Pattern To Allow Most Characters, And No Special Characters
Dim reEmail As Regex = New Regex("([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]
{1,3}\.[0-9]{1,3}\." +
")|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})",
RegexOptions.IgnoreCase _
Or RegexOptions.CultureInvariant _
Or RegexOptions.IgnorePatternWhitespace _
Or RegexOptions.Compiled
)

Dim blnPossibleMatch As Boolean = reEmail.IsMatch(txtEmail.Text)

If blnPossibleMatch Then

'Check If Entered Email Is In Correct Format


If Not txtEmail.Text.Equals(reEmail.Match(txtEmail.Text).ToString) Then

MessageBox.Show("Invalid Email Address!")

Else

EmailValid = True

End If

Else 'Not A Match To Pattern

EmailValid = False 'Set Boolean Variable To False

MessageBox.Show("Invalid Email Address!")

txtEmail.Clear() 'Clear Textbox

txtEmail.Focus() 'Set Focus To TextBox

End If

End Sub
Private Sub btnUpload_Click(sender As Object, e As EventArgs) Handles
btnUpload.Click
OpenFileDialog1.Filter = "Jpeg|*.JPG|Bitmap|*.BMP|Gif|*.GIF"
OpenFileDialog1.RestoreDirectory = True
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = "" Then Exit Sub
idPicture.ImageLocation = OpenFileDialog1.FileName
txtPath.Text = OpenFileDialog1.FileName
End Sub

Private Sub txtPath_TextChanged(sender As Object, e As EventArgs) Handles


txtPath.TextChanged
txtPath.Text = (Replace(txtPath.Text, "\", ";"))
End Sub
Private Sub txtFname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
txtFname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtMname.Focus()
Exit Sub
End If
End Sub

Private Sub txtMname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtMname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtLname.Focus()
Exit Sub
End If
End Sub

Private Sub txtAddress_KeyPress(sender As Object, e As KeyPressEventArgs)


Handles txtAddress.KeyPress
If Asc(e.KeyChar) = 13 Then
txtEmail.Focus()
Exit Sub
End If
End Sub

Private Sub txtEmail_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtEmail.KeyPress
If Asc(e.KeyChar) = 13 Then
txtCP.Focus()
Exit Sub
End If
End Sub

Private Sub txtLname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtLname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtAddress.Focus()
Exit Sub
End If
End Sub

Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles


btnEdit.Click
Dim frm1 = New frmEdit()
frm1.Show()
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles


btnDelete.Click
Dim frm2 = New frmEdit()
frm2.Show()
End Sub

Private Sub txtEmail_Leave(sender As Object, e As EventArgs) Handles


txtEmail.Leave
ValidateEmail()
Exit Sub
End Sub

Private Sub txtLname_Leave(sender As Object, e As EventArgs) Handles


txtLname.Leave
Dim strLastname As String = "^[a-zA-Z\s]+$"

Dim reLastname As New Regex(strLastname) 'Attach Pattern To lastname


Textbox

If Not reLastname.IsMatch(txtLname.Text) Then

MessageBox.Show("Please Enter Alphabetic Characters for LastName!")

txtLname.Clear()

End If
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles


btnClear.Click
clearText()
btnAdd.Enabled = True
btnEdit.Enabled = True
btnDelete.Enabled = True
btnSave.Enabled = False
btnClear.Enabled = False
btnUpload.Enabled = False
idPicture.ImageLocation = "D:\Lecture_programs\installment\InstallmentSys\
photo\default.jpg"
End Sub
End Class

''''''''''''''''''''''''''''''''''''''''''''''''''
''''frmEdit code '''''''''''''''''''
Imports MySql.Data.MySqlClient
Imports System.Text.RegularExpressions
Public Class frmEdit
Private EmailValid As Boolean
Public ds As New DataSet
Private Sub frmEdit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtID.Enabled = False
idPicture.ImageLocation = "D:\Lecture_programs\installment\InstallmentSys\
photo\default.jpg"
loadListView()
End Sub
Private Sub loadListView()
Try
lstInfo.Items.Clear()
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()
MyCon.Open()
MyCommand.Connection = MyCon
MyCommand.CommandText = "SELECT * FROM tblcustomer ORDER BY LNAME"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader
If MySQLData.HasRows Then
While MySQLData.Read
With lstInfo.Items.Add(MySQLData("CUSTOMERID"))
.SubItems.Add(MySQLData("LNAME"))
.SubItems.Add(MySQLData("FNAME"))
.SubItems.Add(MySQLData("MNAME"))
.SubItems.Add(MySQLData("ADDRESS"))
.SubItems.Add(MySQLData("EMAIL"))
.SubItems.Add(MySQLData("CP"))
.SubItems.Add(MySQLData("PICS"))

End With
End While
End If
MyCon.Close()
MySQLData.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles
txtSearch.TextChanged
Try

lstInfo.Items.Clear()

If (MyCon.State = ConnectionState.Open) Then MyCon.Close()

MyCon.Open()
MyCommand.Connection = MyCon

MyCommand.CommandText = "SELECT * FROM tblcustomer WHERE LNAME LIKE


'" & txtSearch.Text.ToUpper() & "%'"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader
If MySQLData.HasRows <> 0 Then
While MySQLData.Read
With lstInfo.Items.Add(MySQLData("CUSTOMERID"))
.SubItems.Add(MySQLData("LNAME"))
.SubItems.Add(MySQLData("FNAME"))
.SubItems.Add(MySQLData("MNAME"))
.SubItems.Add(MySQLData("ADDRESS"))
.SubItems.Add(MySQLData("EMAIL"))
.SubItems.Add(MySQLData("CP"))
.SubItems.Add(MySQLData("PICS"))

End With
End While

Else
lstInfo.Items.Clear()
End If

MyCon.Close()
MySQLData.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub lstInfo_MouseClick(sender As Object, e As MouseEventArgs) Handles


lstInfo.MouseClick
lstInfo.Refresh()

txtID.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(0).Text
txtLname.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(1).Text
txtFname.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(2).Text
txtMname.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(3).Text

txtAddress.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(4).Text
txtEmail.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(5).Text
txtCP.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(6).Text
txtPath.Text = lstInfo.SelectedItems.Item(0).SubItems.Item(7).Text
idPicture.ImageLocation =
Replace(lstInfo.SelectedItems.Item(0).SubItems.Item(7).Text, ";", "\")
End Sub

Private Sub txtSearch_KeyPress(sender As Object, e As KeyPressEventArgs)


Handles txtSearch.KeyPress
If Asc(e.KeyChar) = 8 Then
lstInfo.Items.Clear()
Exit Sub
End If
End Sub

Private Sub btnUpload_Click(sender As Object, e As EventArgs) Handles


btnUpload.Click
OpenFileDialog1.Filter = "Jpeg|*.JPG|Bitmap|*.BMP|Gif|*.GIF"
OpenFileDialog1.RestoreDirectory = True
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = "" Then Exit Sub
idPicture.ImageLocation = OpenFileDialog1.FileName
txtPath.Text = OpenFileDialog1.FileName
End Sub

Private Sub ValidateEmail()

'Set Up Reg Exp Pattern To Allow Most Characters, And No Special Characters
Dim reEmail As Regex = New Regex("([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]
{1,3}\.[0-9]{1,3}\." +
")|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})",
RegexOptions.IgnoreCase _
Or RegexOptions.CultureInvariant _
Or RegexOptions.IgnorePatternWhitespace _
Or RegexOptions.Compiled
)

Dim blnPossibleMatch As Boolean = reEmail.IsMatch(txtEmail.Text)

If blnPossibleMatch Then

'Check If Entered Email Is In Correct Format


If Not txtEmail.Text.Equals(reEmail.Match(txtEmail.Text).ToString) Then

MessageBox.Show("Invalid Email Address!")

Else

EmailValid = True
End If

Else 'Not A Match To Pattern

EmailValid = False 'Set Boolean Variable To False

MessageBox.Show("Invalid Email Address!")

txtEmail.Clear() 'Clear Textbox

txtEmail.Focus() 'Set Focus To TextBox

End If

End Sub

Private Sub txtFname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtFname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtMname.Focus()
Exit Sub
End If
End Sub

Private Sub txtMname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtMname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtLname.Focus()
Exit Sub
End If
End Sub

Private Sub txtLname_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtLname.KeyPress
If Asc(e.KeyChar) = 13 Then
txtAddress.Focus()
Exit Sub
End If
End Sub

Private Sub txtAddress_KeyPress(sender As Object, e As KeyPressEventArgs)


Handles txtAddress.KeyPress
If Asc(e.KeyChar) = 13 Then
txtEmail.Focus()
Exit Sub
End If
End Sub

Private Sub txtEmail_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtEmail.KeyPress
If Asc(e.KeyChar) = 13 Then
txtCP.Focus()
Exit Sub
End If
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles


btnUpdate.Click
If txtFname.Text = "" Or txtLname.Text = "" Or txtCP.Text = "" Or
txtPath.Text = "" Then
MsgBox("Fill-in the required customer information",
MsgBoxStyle.Critical, "ERROR!!!")
Exit Sub
Else
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()
MyCon.Open()

ExecButton("Update tblcustomer Set FNAME='" & txtFname.Text.ToUpper() &


"', MNAME='" & txtMname.Text.ToUpper() & "', LNAME='" & txtLname.Text.ToUpper() &
"',ADDRESS='" & txtAddress.Text.ToUpper() & "', EMAIL='" & txtEmail.Text & "',CP='"
& txtCP.Text & "' , PICS='" & txtPath.Text & "' WHERE CUSTOMERID='" &
txtID.Text.ToString() & "'")
MsgBox("Records have been successfully updated.",
MsgBoxStyle.Information, "Success")
idPicture.ImageLocation = "D:\Lecture_programs\salary\salaryProgram\
photo\default.jpg"
lstInfo.Items.Clear()
txtID.Text = ""
txtFname.Text = ""
txtMname.Text = ""
txtLname.Text = " "
txtAddress.Text = " "
txtEmail.Text = ""
txtCP.Text = ""
txtPath.Text = ""

End If

End Sub

Private Sub txtPath_TextChanged(sender As Object, e As EventArgs) Handles


txtPath.TextChanged
txtPath.Text = (Replace(txtPath.Text, "\", ";"))
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles


btnDelete.Click
Try
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()
MyCon.Open()
If (lstInfo.Items.Count > 0) Then
Dim result = MessageBox.Show("Are you sure you want to delete this
record?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If result = DialogResult.No Then
MessageBox.Show("Action Canceled.")

Exit Sub
ElseIf result = DialogResult.Yes Then
strsql = "DELETE FROM tblcustomer WHERE CUSTOMERID = '" &
txtID.Text & "'"
Dim da As New MySqlDataAdapter(strsql, MyCon)
da.Fill(ds)
MsgBox("Record was deleted successfully!",
MsgBoxStyle.Information, "Delete Data Success")
MyCon.Close()
lstInfo.Items.Clear()
txtID.Text = ""
txtFname.Text = ""
txtMname.Text = ""
txtLname.Text = ""
txtAddress.Text = ""
txtEmail.Text = ""
txtCP.Text = ""
txtPath.Text = ""
idPicture.ImageLocation = "D:\Lecture_programs\salary\
salaryProgram\photo\default.jpg"
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub txtLname_Leave(sender As Object, e As EventArgs) Handles


txtLname.Leave
Dim strLastname As String = "^[a-zA-Z\s]+$"

Dim reLastname As New Regex(strLastname) 'Attach Pattern To lastname


Textbox

If Not reLastname.IsMatch(txtLname.Text) Then

MessageBox.Show("Please Enter Alphabetic Characters for LastName!")

txtLname.Clear()

End If
End Sub

Private Sub txtEmail_Leave(sender As Object, e As EventArgs) Handles


txtEmail.Leave
ValidateEmail()
End Sub
End Class

''''''''''''''''''''''
'''DBconnection code ''''''''''
Imports MySql.Data.MySqlClient
Module DBConnection
Public newrecord As Boolean
Public MyAdapter As New MySqlDataAdapter
Public dt As New DataTable
Public num As Integer
Public MyCommand As New MySqlCommand
Public strsql As String
Public command As New MySqlCommand
Public reader As MySqlDataReader
Public sqlAdapter As New MySqlDataAdapter
Public query As String
Public MyCon As MySqlConnection = New
MySqlConnection("datasource=localhost;uid=root;database=installment;")
Public Sub ExecButton(ByVal query)
Try
If (MyCon.State = ConnectionState.Open) Then
MyCon.Close()
End If
MyCon.Open()

MyCommand.Connection = MyCon
MyCommand.CommandText = query
MyAdapter.SelectCommand = MyCommand
Dim MyData As MySqlDataReader = MyCommand.ExecuteReader
MyCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Public Function getMaxNumber()


Try

If (MyCon.State = ConnectionState.Open) Then


MyCon.Close()
End If
MyCon.Open()
MyCommand.Connection = MyCon
MyCommand.CommandText = "SELECT MAX(C_ID) AS MAX_NUM FROM tblcustomer"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader
If MySQLData.HasRows Then
MySQLData.Read()
num = Convert.ToInt32(MySQLData("MAX_NUM")) '1
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
If num = 1 Then
getMaxNumber = 1
Else
'getMaxNumber = ((num - 1) + 1)
getMaxNumber = num
End If
End Function
End Module
''''''''''''''''''''''''''
''''''''''''modeData module code '''''''''''
Module ModData
Public Sub modeObject(ByVal sform As String)
If sform = "frmCreateUser" Then
With frmCreateUser
.txtUser.Text = ""
.txtPassword.Text = ""
End With
ElseIf sform = "frmCustomer" Then
With frmCustomer
.txtID.Text = ""
.txtFname.Text = ""
.txtLname.Text = ""
.txtCP.Text = ""
.txtMname.Text = ""
.txtAddress.Text = ""
.txtEmail.Text = ""
.txtPath.Text = ""
.btnSave.Enabled = False
.txtID.Enabled = False
.txtFname.Enabled = False
.txtMname.Enabled = False
.txtLname.Enabled = False
.txtAddress.Enabled = False
.txtCP.Enabled = False
.txtEmail.Enabled = False
.btnClear.Enabled = False
.btnUpload.Enabled = False
.btnAdd.Enabled = True
.btnEdit.Enabled = True
.btnDelete.Enabled = True

End With
End If
End Sub
End Module

''''''''''''''''''''''''''''''
'''frmUpdateRecord
Imports MySql.Data.MySqlClient
Public Class FrmUpdateRecord
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles
txtSearch.TextChanged
Try

lstInfo.Items.Clear()
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()
MyCon.Open()
MyCommand.Connection = MyCon

MyCommand.CommandText = "SELECT * FROM student WHERE LNAME LIKE '" &


txtSearch.Text.ToUpper() & "%'"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader
If MySQLData.HasRows Then
While MySQLData.Read
With lstInfo.Items.Add(MySQLData("IDNUMBER"))
.SubItems.Add(MySQLData("FNAME"))
.SubItems.Add(MySQLData("MNAME"))
.SubItems.Add(MySQLData("LNAME"))
.SubItems.Add(MySQLData("COURSE"))
.SubItems.Add(MySQLData("ADDRESS"))
.SubItems.Add(MySQLData("DOB"))
End With
End While
End If
MyCon.Close()
MySQLData.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub lstInfo_MouseDoubleClick(sender As Object, e As MouseEventArgs)
Handles lstInfo.MouseDoubleClick

FrmUpdateEntry.txtID.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(0).Text
FrmUpdateEntry.txtFname.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(1).Text
FrmUpdateEntry.txtMname.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(2).Text
FrmUpdateEntry.txtLname.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(3).Text
FrmUpdateEntry.cboCourse.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(4).Text
FrmUpdateEntry.txtAddress.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(5).Text
FrmUpdateEntry.txtDOB.Text =
lstInfo.SelectedItems.Item(0).SubItems.Item(6).Text
FrmUpdateEntry.Show()
Me.Close()
End Sub
Sub view()
Try
lstInfo.Items.Clear()
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()
MyCon.Open()
MyCommand.Connection = MyCon
MyCommand.CommandText = "SELECT * FROM student ORDER BY LNAME LIMIT 5"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader
If MySQLData.HasRows Then
While MySQLData.Read
With lstInfo.Items.Add(MySQLData("IDNUMBER"))
.subitems.add(MySQLData("FNAME"))
.subitems.add(MySQLData("MNAME"))
.subitems.add(MySQLData("LNAME"))
.subitems.add(MySQLData("COURSE"))
.subitems.add(MySQLData("ADDRESS"))
.subitems.add(MySQLData("DOB"))
End With
End While
End If
MyCon.Close()
MySQLData.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub FrmUpdateRecord_Load(sender As Object, e As EventArgs) Handles


MyBase.Load
view()
End Sub
End Class

'''''''''''''''''''''''''''
'''''frmUpdateEntry''''''''
Imports MySql.Data.MySqlClient
Public Class FrmUpdateEntry
Private Sub FrmUpdateEntry_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
txtID.Enabled = False
FillCourse()
End Sub
Sub FillCourse()

Try
MyCon.Open()
MyCommand.Connection = MyCon
MyCommand.CommandText = "SELECT * FROM course"
MyAdapter.SelectCommand = MyCommand
Dim MySQLData As MySqlDataReader = MyCommand.ExecuteReader

While (MySQLData.Read())
cboCourse.Items.Add(MySQLData("COURSE_NAME"))
End While
MyCon.Close()
MySQLData.Close()
Catch ex As Exception
MsgBox(ex.Message)

End Try
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles


btnSave.Click
Try
If (MyCon.State = ConnectionState.Open) Then MyCon.Close()

ExecButton("Update student SET FNAME='" & txtFname.Text.ToUpper() & "',


MNAME='" & txtMname.Text.ToUpper() & "', LNAME='" & txtLname.Text.ToUpper() & "',
COURSE='" & cboCourse.Text.ToUpper() & "', ADDRESS='" & txtAddress.Text.ToUpper() &
"', DOB='" & txtDOB.Text & "' WHERE IDNUMBER='" & txtID.Text & "'")
MsgBox("Records have been successfully updated.",
MsgBoxStyle.Information, "Success")

MyCon.Close()
FrmUpdateRecord.Show()
Me.Close()

Catch ex As Exception
MsgBox(ex.Message)

End Try
End Sub
End Class

You might also like