Professional Documents
Culture Documents
Data Code
Data Code
Data Code
cn.ConnectionString = constr
cn.Open()
Dim sql As String
sql = "Update DataBase set " & _
"[SecondName] = '" & TextBox2.Text.ToString & "',[FirstName] = '" &
TextBox1.Text & "', [LastName] = '" & TextBox3.Text & "' , [Department] ='" &
ComboBox1.Text & "' ,[School]='" & ComboBox2.Text & "', [Gender] = '" & ComboBox3.Text &
"' , [State] ='" & ComboBox4.Text & "' ,[LocalGovt]='" & TextBox5.Text & "' ,[Age] ='" &
TextBox6.Text & "' " & _
"Where MatricNumber = " & TextBox4.Text & ""
Dim command As OleDbCommand = New OleDbCommand(sql, cn)
Try
With command
.Connection = cn
.CommandType = CommandType.Text
.CommandText = sql
End With
command.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, vbCritical)
cn.Close()
Finally
cn.Dispose()
cn.Close()
End Try
Submit:
If TextBox4.Text = "" Then
MsgBox("Enter Student Matric Number", MsgBoxStyle.Exclamation)
Exit Sub
End If
cn.ConnectionString = constr
cn.Open()
Dim str As String
str = "Insert Into [DataBase]
([ID],[MatricNumber],[LastName],[FirstName],[SecondName],[Department],[School],[Gender],[
State],[LocalGovt],[Age]) VALUES (?,?,?,?,?,?,?,?,?,?,?) "
Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
Dim id As String = TextBox4.Text.Substring(13)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
cn.Close()
MsgBox("Data Successfully Saved")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
ComboBox1.Text = String.Empty
ComboBox2.Text = String.Empty
ComboBox3.Text = String.Empty
ComboBox4.Text = String.Empty
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
cn.Close()
Exit Sub
End Try
Retrieve:
Dim matno, n As String
matno = InputBox("Enter Student Matric Number", "Search Student",
"ND2017/1010/002")
Try
cn.ConnectionString = constr
cn.Open()
cm.Connection = cn
While dr.Read
found = True
TextBox1.Text = dr("FirstName").ToString
TextBox2.Text = dr("SecondName").ToString
TextBox3.Text = dr("LastName").ToString
TextBox4.Text = dr("MatricNumber").ToString.ToUpper
ComboBox1.Text = dr("Department").ToString
ComboBox2.Text = dr("School").ToString
ComboBox3.Text = dr("Gender").ToString
ComboBox4.Text = dr("State").ToString
TextBox5.Text = dr("LocalGovt").ToString
TextBox8.Text = dr("Age").ToString
End While
cn.Close()
If found = False Then
MsgBox("Student Matric Number not found.", MsgBoxStyle.Critical)
dr.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
cn.Close()
End Try
Delete:
Dim hos, path, matno, link As String
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
cn.Close()
End Try
Clear:
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
ComboBox1.Text = String.Empty
ComboBox2.Text = String.Empty
ComboBox3.Text = String.Empty
ComboBox4.Text = String.Empty
TextBox1.Focus()