what error message message do you get?
Netcode
Veteran Poster
1,037 posts since Jun 2009
Reputation Points: 43
Solved Threads: 70
Skill Endorsements: 0
From looking at your code:
Line 6:
tbStudent = sqlDataset.Tables("Major")
Is sqlDataSet filled with data?
Line 17:
drSubject = tbStudent.Rows.Find(major)
Is your TextBox1 filled?
Line 31 - 33
TextBox1.Text = drSubject.Item("MajorName")
TextBox2.Text = drSubject.Item("Departement")
TextBox3.Text = drSubject.Item("Suject_Name")
You pull data from Line 21, and read it in Line 27 - 36, but the textboxes are pulling data from drSubject and not the reader (declared dr in Line 23). Also, Lines 21 and 33 is the field Suject or Subject?
Possible Lines 31-33 should be:
TextBox1.Text = dr.Item("MajorName")
TextBox2.Text = dr.Item("Departement")
TextBox3.Text = dr.Item("Suject_Name")
Maligui
Junior Poster in Training
84 posts since Aug 2012
Reputation Points: 0
Solved Threads: 17
Skill Endorsements: 2
It looks like you are trying to use the same objects for every operation. Try to avoid this since it is back practice and may cause exceptions when two methods are trying to access the same oject at the same time - such as this case. Your data reader (dr) was already being used somewhere else. and since it was not closed, the reader is still open.
After your read is finished reading use the dr.Close method.
'''''check from here
While dr.Read
tbStudent.Rows.Add()
TextBox1.Text = dr.Item("MajorName")
TextBox2.Text = dr.Item("Departement")
TextBox3.Text = dr.Item("Suject_Name")
End While
' Close the reader
dr.Close()
Best practice is that you scope your objects to where they are needed. This will avoid memory locks, and helps the overall readability of the design. For example, your data reader is really only needed here. So, you should declare a datareader for the scope of this method. That way is is disposed after the method executes.
Maligui
Junior Poster in Training
84 posts since Aug 2012
Reputation Points: 0
Solved Threads: 17
Skill Endorsements: 2
Did you assign it?
Dim MyNewDataReader As OleDbDataReader = command.ExecuteScalar
What line is the error comming from?
Maligui
Junior Poster in Training
84 posts since Aug 2012
Reputation Points: 0
Solved Threads: 17
Skill Endorsements: 2
Question Answered as of 9 Months Ago by
Maligui,
Netcode
and
HibaPro