Retreiving data from previous form to next form

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2009
Posts: 105
Reputation: Piya27 is an unknown quantity at this point 
Solved Threads: 8
Piya27's Avatar
Piya27 Piya27 is offline Offline
Junior Poster

Retreiving data from previous form to next form

 
0
  #1
Jul 3rd, 2009
Hi All,

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.

  1.  
  2. Public Class PersonalDetail
  3. Public enrolmentno As Integer
  4. ....
  5. End Class
  6.  
  7. ....
  8.  
  9. Public Class ParentDetail
  10.  
  11. Public Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
  12.  
  13. Dim obj As New PersonalDetail
  14.  
  15. Dim _enrol As Integer
  16. ...
  17. _enrol = obj.enrolmentno ' this shows the value 0 in the form
  18. ....
  19. End Sub
  20. ....
  21. 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.
  1. Dim dr As SqlDataReader
  2. Dim er As Integer
  3. Dim cmd1 As SqlCommand
  4.  
  5. con = New SqlConnection("Server=localhost;" & "DataBase=SCHOOL;" & "Integrated Security=SSPI")
  6. cmd1 = New SqlCommand("SELECT * FROM PERSONALDETAIL ", con)
  7. dr = cmd1.ExecuteReader
  8.  
  9. While dr.Read
  10. _er = dr.GetInt32(0)
  11. _enrol = er
  12. End While
  13. dr.Close()
  14.  
  15. 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.

Thanks.
Regards,
Piya:)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 464
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Retreiving data from previous form to next form

 
0
  #2
Jul 3rd, 2009
Here, I have two froms:

Form1
  1. public Class Form1
  2. public dataForm1 as Integer
  3. ......
  4. Sub button1_click(..)
  5. Form2.dataForm2=10
  6. Form2.Show()
  7. End Sub
  8. End Class

Form2
  1. public Class Form2
  2. public dataForm2 as Integer
  3. ......
  4. Sub button1_click(..)
  5. MsgBox("Data from Form1 " & dataForm2)
  6. Form1.dataForm1=20
  7. Form1.Label1.Text="Test"
  8. End Sub
  9. End Class
Last edited by adatapost; Jul 3rd, 2009 at 10:09 am.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Retreiving data from previous form to next form

 
0
  #3
Jul 3rd, 2009
For the latter approach
I couldn't findout how to retrieve the last entered columns field using ExecuteRead
use
  1. Dim oCmd As SqlCommand
  2. .
  3. .
  4. strSQL = "INSERT INTO <table> (<fields>) VALUES (<values>)"
  5. strSQL = strSQL & "; SELECT @@IDENTITY AS 'Identity' "
  6. oCmd.CommandText = strSQL
  7.  
  8. NewIdentity = CInt(oCmd.ExecuteScalar())
in your insert statement. See Save binary data to SQL Server with VB.NET in my blog for a more complete example.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC