Click here to Skip to main content
15,662,484 members
Please Sign up or sign in to vote.
4.71/5 (5 votes)
See more:
Hello all,
I have this nagging error which i have applied common knowledge to solve it but could not. in the code segment below, I want to be able to loop through a dataset to extract value, but i keep getting the error as metioned "object reference not set to an instance......". as u can c, the objects i used are instantiated, please can anyone help solve this problem?

<br />Dim dset1 As DataSet<br />Dim dt As DataTable<br />                dSet1 = New DataSet<br />                'The adapter stores the data in a dataset<br />                dAdapt1.Fill(dSet1, "Patient Profile")<br /><br />dt = New DataTable<br />                dt = dSet1.Tables("Patient_Profile")<br /><br /> For Each rw As DataRow In dt.Rows  --> Error Object reference not set to an instance of an object.<br />                    decdata = New TripleDES()<br />                   <br />                    deRecDataFnam = decdata.Decrypt(rw("FirstName"), ned)<br />                    listItem = New ListViewItem()<br />                    listItem.SubItems.Add(deRecDataFnam)<br /><br />                    ListVwPatProf.Items.Add(listItem)<br />                Next<br />

Thanks a lot!

ChiSmile wrote:
dAdapt1.Fill(dSet1, "Patient Profile")

ChiSmile wrote:
dt = dSet1.Tables("Patient_Profile")

Do you see the problem there? Here's a hint - you've got a magic string issue - when you use a string in one place to name something, you've got to use the same name whenever you refer to it.

Now, here's a piece of advice - learn how to debug. If you had set a breakpoint and stepped over your code (pausing to explore the values as you were debugging), you'd have found this issue straightaway.

Share this answer
ChiSmile wrote:
dt = New DataTable<br />dt = dSet1.Tables("Patient_Profile")

Yes, you're indeed initializing dt, but then you're reassigning it the value of dSet1.Tables("Patient_Profile"). Make sure you actually have a table in dSet1 called Patient_Profile.

Share this answer

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900