Reputation: 1
I'm working on a very basic VB.net frontend for an Access database and have stumbled upon a problem.
Dim ds As DataSet
MaxRows = ds.Tables("Course_assignmentsDataSet.tblCourse").Rows.Count
i = 0
Private Sub Navigate()
txtCourseReference.Text = ds.Tables("Course_assignmentsDataSet.tblCourse").Rows(i).Item(1)
txtCourseName.Text = ds.Tables("Course_assignmentsDataSet.tblCourse").Rows(i).Item(2)
End Sub
I get the error that Object Reference is not set to an instance of an Object. I think this is because I haven't defined the DataSet as "Course_assignmentsDataSet"- the one I want to use- but I'm not sure how to do this.
Can anyone help?
Upvotes: 0
Views: 250
Reputation: 10452
Your dataset needs to be instantiated using the "New" keyword. The object reference in this case is ds, and it's just set to type dataset. New creates an "instance" of the DataSet.
Dim ds as New Course_assignmentsDataSet
Then you'll want to do:
txtCourseReference.Text = ds.Tables("tblCourse").Rows(i).Item(1)
txtCourseName.Text = ds.Tables("tblCourse").Rows(i).Item(2)
Edit: As Jay said below, you'll want to fill the dataset first
Upvotes: 0