I am working on a windows application in vb.net. (School Management Project).
My problem is that, when I am adding the Personal Details of a student,(which include enrolmentno(primary key in the database),name,class,section,etc), when I click the save button what I want is that the enrolmentno should appear on the ParentDetail Form without again entering it. (later that would be used as a foreign key to the PARENTDETAIL table in the database), but I am not able to get the value of enrolmentno from my previous form to the next form.
I declared the variable as Public in the PersonalDetail Form and then tried to access that variable in the ParentDetail Form by instantiating the object of the previous form, but that doesnt work.
Public Class PersonalDetail Public enrolmentno As Integer .... End Class .... Public Class ParentDetail Public Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click Dim obj As New PersonalDetail Dim _enrol As Integer ... _enrol = obj.enrolmentno ' this shows the value 0 in the form .... End Sub .... End Class
I also tried to get the value of enrolmentno from the database using the ExecuteRead command. but I couldn't findout how to retrieve the last entered columns field using ExecuteRead.
Dim dr As SqlDataReader Dim er As Integer Dim cmd1 As SqlCommand con = New SqlConnection("Server=localhost;" & "DataBase=SCHOOL;" & "Integrated Security=SSPI") cmd1 = New SqlCommand("SELECT * FROM PERSONALDETAIL ", con) dr = cmd1.ExecuteReader While dr.Read _er = dr.GetInt32(0) _enrol = er End While dr.Close() End Sub
'but this enters the value of the first record int the database.
I am new to VB.Net. Please Help. I hope my problem is clear.