Dataset Error - non object reference

banks

Well-known member
Joined
Sep 7, 2005
Messages
50
Programming Experience
Beginner
Hi, i tried using your method - couldn't get it to work

I have tried this and it also doent work as it says object reference not instance of object on the top line:-

VB.NET:
    Private Sub NavigateRecords()

        txtUsername.Text = ds.Tables("Users").Rows(inc).Item("LoginName")
        txtPassword.Text = ds.Tables("Users").Rows(inc).Item(2)
        txtFullName = ds.Tables("Users").Rows(inc).Item(3)


    End Sub

I am filling the dataset using this:-

VB.NET:
Private Sub frmUserData_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet("Users")

        Dim strSQL As String
        Dim conn As OleDbConnection = carDba.getCn

        strSQL = "SELECT UserId, LoginName, LoginPassword, userLevelId, fullName " & _
        "FROM tblUser"
        Dim da As New OleDbDataAdapter(strSQL, conn)
        da.Fill(ds, "Users")

        'txtUsername.Text = ds.Tables("UserId").Rows(0).Item(2)

        MaxRows = ds.Tables("Users").Rows.Count
        inc = -1
    End Sub

And navigating through the records like this:- (which doesnt work)

VB.NET:
    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            NavigateRecords()
        Else
            MsgBox("No More Rows")
        End If
    End Sub

Anyone see the error in my ways?....

Alex
 
txtUsername.Text = ds.Tables("Users").Rows(inc).Item("LoginName")

Your problem is most likely the ds.tables... part. You dimensioned a dataset in the load event, but this is a local variable and only accessible in that method. If you want that dataset to become visible to the whole class then you need to declare it as a class level variable. Place this somewhere below the windows forms designer generated bit...

VB.NET:
Private Ds as new system.data.dataset
 
yeah thats what it was, cheers.

how do i get the first record to display? at the moment i have to press my next record button to pull up the first record - i'd like it there on load if possible

Alex
 
At the end of the load event....

VB.NET:
BtnNext.PerformClick

It might even work!! If it doesn't though all you need to do is set inc to the row you want it to display, then call your navigaterecords procedure. You may also want to look into databinding, contrary to another thread i posted in on this subject, databinding may well be of use in this situation.
 
vis781 said:
At the end of the load event....

VB.NET:
BtnNext.PerformClick
You may also want to look into databinding, contrary to another thread i posted in on this subject, databinding may well be of use in this situation.

How could you vis? :D
 
Back
Top