pls help..iv juz started learning vb.net..encountered this problem in this code:

Private Sub NavigateRecords()

        TextBox1.Text = ds.Tables("stdDataSet").Rows(inc).Item(0)-error msg appeared here sayin null reference evception was unhandled. Object reference not set to an instance of an object.
        TextBox2.Text = ds.Tables("stdDataSet").Rows(inc).Item(1)
        TextBox3.Text = ds.Tables("stdDataSet").Rows(inc).Item(2)
        TextBox4.Text = ds.Tables("stdDataSet").Rows(inc).Item(3)

this is the full coding:

Public Class Form1
    Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String
    Dim sql As String
    Dim da As OleDb.OleDbDataAdapter
    Dim ds As New DataSet
    Dim inc As Integer
    Dim MaxRows As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source = std.accdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "SELECT * FROM Table1"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "stdDataSet")

        MsgBox("Database is now open")
        inc = -1
        MaxRows = ds.Tables("stdDataSet").Rows.Count

        con.Close()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            NavigateRecords()
        Else
            MsgBox("No more Rows")

        End If
    End Sub
    Private Sub NavigateRecords()

        TextBox1.Text = ds.Tables("stdDataSet").Rows(inc).Item(0)
        TextBox2.Text = ds.Tables("stdDataSet").Rows(inc).Item(1)
        TextBox3.Text = ds.Tables("stdDataSet").Rows(inc).Item(2)
        TextBox4.Text = ds.Tables("stdDataSet").Rows(inc).Item(3)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If inc > 0 Then
            inc = inc - 1
            NavigateRecords()
        Else

            MsgBox("First Record")

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If inc <> -1 Then
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow
            dsNewRow = ds.Tables("stdDataSet").NewRow()
            dsNewRow.Item("Studentname") = TextBox1.Text
            dsNewRow.Item("School") = TextBox2.Text
            dsNewRow.Item("Age") = TextBox3.Text
            dsNewRow.Item("Grade") = TextBox4.Text

            ds.Tables("stdDataSet").Rows.Add(dsNewRow)
            da.Update(ds, "stdDataSet")
            MsgBox("New Record added to the Database")

            Button1.Enabled = True
            Button2.Enabled = True

        End If
        MaxRows = ds.Tables("stdDataSet").Rows.Count
        inc = 0
        NavigateRecords()

        

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = ("")
        TextBox2.Text = ("")
        TextBox3.Text = ("")
        TextBox4.Text = ("")


    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("stdDataSet").Rows(inc).Item(0) = TextBox1.Text
        ds.Tables("stdDataSet").Rows(inc).Item(1) = TextBox2.Text
        ds.Tables("stdDataSet").Rows(inc).Item(2) = TextBox3.Text
        ds.Tables("stdDataSet").Rows(inc).Item(3) = TextBox4.Text

        da.Update(ds, "stdDataSet")

        MsgBox("Data updated")



    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        If MessageBox.Show("Do you really want to Delete this Record?", _
"Delete", MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning) = DialogResult.No Then


            MsgBox("Operation Cancelled")
            Exit Sub

        End If
        ds.Tables("stdDataSet").Rows(inc).Delete()
        MaxRows = MaxRows - 1
        da.Update(ds, "stdDataSet")
        inc = 0
        NavigateRecords()

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If TextBox1.Text = "Adam" Then
            inc = 0
        ElseIf TextBox1.Text = "Ahmad" Then
            inc = 1
        ElseIf TextBox1.Text = "Sofia" Then
            inc = 2
        ElseIf TextBox1.Text = "Sarah" Then
            inc = 3
        End If
        NavigateRecords()



    End Sub



    
End Class

pls help..:(

im using microsoft access 2007 for my database and microsoft visual studio 2008...i already upgraded the visual studio with SP1..plssssssss helpppp!

you can enter these lines of code in areas where you have such errors. you have to convert the rows in a datatable to type 'string before' you can place them in textboxes.

For Each myDataRow As DataRow In objdatatable.Rows

              TextBox1.Text = Convert.ToString(myDataRow("item1"))
              TextBox2.Text = Convert.ToString(myDataRow("item2"))
              TextBox3.Text = Convert.ToString(myDataRow("item3"))
              TextBox4.Text = Convert.ToString(myDataRow("item4"))
                
                          
            Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.