0% found this document useful (0 votes)
30 views3 pages

Private Sub Btnupdate

This document contains code for updating, searching, and deleting records from a student information database table. It includes code to: 1. Update field values in the student table based on values entered in textboxes and selected in dropdowns, and check if the record was successfully updated. 2. Search the student table by student number, load the record details into textboxes and dropdowns, and display the student image. 3. Delete a record from the student table by student number and check if the record was successfully deleted.

Uploaded by

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

Private Sub Btnupdate

This document contains code for updating, searching, and deleting records from a student information database table. It includes code to: 1. Update field values in the student table based on values entered in textboxes and selected in dropdowns, and check if the record was successfully updated. 2. Search the student table by student number, load the record details into textboxes and dropdowns, and display the student image. 3. Delete a record from the student table by student number and check if the record was successfully deleted.

Uploaded by

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

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.

EventArgs)
Handles btnUpdate.Click
Dim Query As String
Call SISconn()
'Try
Query = "UPDATE tblstudentinfo SET LastName = '" + txtLastName.Text + "',
FirstName = '" + txtFirstName.Text + "', MI '" + txtStudMiddleInitial.Text + "', Age '" +
txtAge.Text + "', Course '" + txtStudCourse.Text + "', Sex '" + cboSex.Text + "',
SubjectCode '" + txtStudSubjCode.Text + "', Major '" + txtStudMajor.Text + "', YearLevel
'" + txtStudYrLevel.Text + "', Instructor '" + txtStudInstructor.Text + "', HomeAddress
'" + txtStudHomeAddress.Text + "', ContactNo '" + txtStudContactNo.Text + "', BirthDate
'" + txtStudBirthDate.Text + "', PlaceOfBirth '" + txtStudPlaceOfBirth.Text + "',
Nationality '" + txtStudNationality.Text + "', Guardian '" + txtStudGuardian.Text + "',
Address '" + txtStudAddress.Text + "', Semester '" + cboSemester.Text + "', Description
'" + txtStudDescription.Text + "', Status '" + cboStudStatus.Text + "', EmailAddress '" +
txtStudEmailAddress.Text + "', Religion '" + txtStudReligion.Text + "', CivilStatus '" +
cboStudCivilStatus.Text + "' NumberOfChildren '" + txtStudNumberOfChildren.Text + "',
IfMarried '" + txtStudIfMarried.Text + "', BoardingHouseAdd '" + txtBoadingHouseAdd.Text
+ "', StudentImage " ' WHERE StudentNo = '" + txtStudentNumber.Text + "'"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
'Call Display()
If (i > 0) Then
MsgBox("Record is Successfully Updated", MsgBoxStyle.Information)
' Call clear()
Else
MsgBox("Record is not Updated", MsgBoxStyle.Exclamation)
End If
'Catch ex As Exception
'MsgBox("Search Record to Update", MsgBoxStyle.Exclamation)
txtStudentNumber.Focus()
'End Try
con.Close()
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSearch.Click
Dim arrImage() As Byte
'Try
con.Open()
sql = ("SELECT * FROM tblstudentinfo WHERE StudentNo = " + txtStudentNumber.Text
+ "")
cmd = New MySqlCommand(sql, con)
readImage = cmd.ExecuteReader()
readImage.Read()
arrImage = readImage.Item("StudentImage")
Dim mstream As New System.IO.MemoryStream(arrImage)
picStudent.Image = Image.FromStream(mstream)
readImage.Close()
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
DataAdapter1.SelectCommand = cmd
DataAdapter1.Fill(ds, "StudentNo")

With dgvStudentNum
.DataSource = ds
.DataMember = "StudentNo"
.Columns(0).Width = 70
.Columns(1).Width = 200
.Columns(2).Width = 300
.ReadOnly = True
.MultiSelect = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.ShowRowErrors = False
.ShowCellErrors = False
.AllowUserToAddRows = False
.AllowUserToResizeColumns = False
.AllowUserToResizeRows = False
.RowHeadersVisible = False
.DefaultCellStyle.SelectionBackColor = Color.LightSalmon
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen

End With
'con.Open()
da.SelectCommand = cmd
da.Fill(dt)
i = dt.Rows.Count
If i > 0 Then
'txtStudentNumber.Text = dt.Rows(0).Item(1)
txtLastName.Text = dt.Rows(0).Item(1)
txtFirstName.Text = dt.Rows(0).Item(2)
txtStudMiddleInitial.Text = dt.Rows(0).Item(3)
txtAge.Text = dt.Rows(0).Item(4)
cboSex.Text = dt.Rows(0).Item(5)
txtStudSubjCode.Text = dt.Rows(0).Item(6)
txtStudMajor.Text = dt.Rows(0).Item(7)
txtStudYrLevel.Text = dt.Rows(0).Item(8)
txtStudInstructor.Text = dt.Rows(0).Item(9)
txtStudHomeAddress.Text = dt.Rows(0).Item(10)
txtStudContactNo.Text = dt.Rows(0).Item(11)
txtStudBirthDate.Text = dt.Rows(0).Item(12)
txtStudPlaceOfBirth.Text = dt.Rows(0).Item(13)
txtStudNationality.Text = dt.Rows(0).Item(14)
txtStudGuardian.Text = dt.Rows(0).Item(15)
txtStudAddress.Text = dt.Rows(0).Item(16)
cboSemester.Text = dt.Rows(0).Item(17)
txtStudDescription.Text = dt.Rows(0).Item(18)
cboStudStatus.Text = dt.Rows(0).Item(19)
txtStudEmailAddress.Text = dt.Rows(0).Item(20)
txtStudReligion.Text = dt.Rows(0).Item(21)
cboStudCivilStatus.Text = dt.Rows(0).Item(22)
txtStudNumberOfChildren.Text = dt.Rows(0).Item(23)
txtStudIfMarried.Text = dt.Rows(0).Item(24)
txtBoadingHouseAdd.Text = dt.Rows(0).Item(25)
txtStudCourse.Text = dt.Rows(0).Item(26)
dt.Reset()
lblFullName.Text = txtLastName.Text + " , " + txtFirstName.Text + " " +
txtStudMiddleInitial.Text.First + "."
Else
MsgBox("No Record Found!", MsgBoxStyle.Critical, "Record Not Found")
txtStudentNumber.Focus()

End If
'Catch ex As Exception
'MsgBox("Please enter StudentNo to search", MsgBoxStyle.Exclamation)
txtStudentNumber.Focus()
'End Try
con.Close()
da.Dispose()
Me.Refresh()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnDelete.Click
Dim Query As String
Call SISconn()
If txtStudentNumber.Text = "" Then
MsgBox("Enter StudentNumber if you want to delete record",
MsgBoxStyle.Exclamation)
txtStudentNumber.Focus()
Else
con.Open()
Query = "Delete FROM tblstudentinfo WHERE StudentNo = " +
txtStudentNumber.Text + ""
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
Call Display()
If (i > 0) Then
MsgBox("Record is Successfully Deleted", MsgBoxStyle.Information)
' Call clear()
Else
MsgBox("Record is not Deleted", MsgBoxStyle.Exclamation)

End If
con.Close()
End If
End Sub

You might also like