0% found this document useful (0 votes)
40 views2 pages

Student Registration App Code

The document contains code for a student registration form application in Visual Basic. It defines functions for loading the form, saving new student data to a database table on button click, and searching the table by registration number to populate the form fields.
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)
40 views2 pages

Student Registration App Code

The document contains code for a student registration form application in Visual Basic. It defines functions for loading the form, saving new student data to a database table on button click, and searching the table by registration number to populate the form fields.
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/ 2

Imports System.

Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Data.DataSet

Public Class Form1


Dim Constring As String
Dim ds As New DataSet
Dim da As SqlDataAdapter
Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Constring = "Data Source = LAPTOP-UE9ULO4B\SQLEXPRESS; initial catalog =
StudentsRegistrationDB; integrated Security = True"
End Sub

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


btnSave.Click
Dim mgender As String
If rbnmale.Checked = True Then
mgender = "Male"
Else
mgender = "Female"
End If
Dim sqlinsert As String
sqlinsert = "insert into StudentRegistration (
StudentRegistrationNo,
FullName,
DOB,
Gender,
Nationality,
Sfp,
Fufu,
Rice,
Banku,
Indomie)
values
('" & txtStudentRegistrationNo.Text
& "',
'" & txtFullName.Text & "',
'" & dtpDOB.Value & "',
'" & mgender & "',
'" & cboNationality.Text & "',
'" & txtSfp.Text & "',
'" & chkFufu.CheckState & "',
'" & chkRice.CheckState & "',
'" & chkBanku.CheckState & "',
'" & chkIndomie.CheckState & "')"

da = New SqlDataAdapter(sqlinsert, Constring)


da.Fill(ds, "StudentsRegistrationDA")
MessageBox.Show("Data succesfully saved")
btnSave.Enabled = False
End Sub

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


btnSearch.Click
Dim mGender As String
Dim sqlSearch As String = "SELECT* from StudentsRegistration WHERE
(StudentRegistrationNo=@StudentRegistrationNo)"
Dim mySqlDBConnection As New SqlConnection(Constring)
Dim mySqlDBCommand As New SqlCommand(sqlSearch, mySqlDBConnection)
mySqlDBCommand.Parameters.AddWithValue("@StudentRegistrationNo",
txtStudentRegistrationNo.Text)
mySqlDBConnection.Open()
Using myDataReader As SqlDataReader = mySqlDBCommand.ExecuteReader()
If myDataReader.Read() Then
txtFullName.Text = myDataReader.Item("FullName").ToString
dtpDOB.Value = myDataReader.Item("DOB").ToString
cboNationality.Text = myDataReader.Item("Nationality").ToString
mGender = myDataReader.Item("Gender").ToString
If Trim(mGender) = "Male" Then
rbnmale.Checked = True
Else
rbnfemale.Checked = True
End If
chkFufu.Checked = myDataReader.Item("H_Fufu").ToString
chkRice.Checked = myDataReader.Item("H_Rice").ToString
chkBanku.Checked = myDataReader.Item("H_Banku").ToString
chkIndomie.Checked = myDataReader.Item("H_Indomie").ToString
Else
MessageBox.Show("Invalid StudentRegistrationNo")
End If

End Using
mySqlDBConnection.Close()
End Sub
End Class

You might also like