0

I am trying to add a new row to an access database using vb however I am receiving this error - Additional information: Object reference not set to an instance of an object. Can anyone see where I can fix this issue?

Public Class frmLecturer


    Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0" &
    "Data Source = StudentDatabase1.accdb")
    Dim objStudentDA As New OleDb.OleDbDataAdapter("Select * FROM StudentDatabase", objConnection)

    Dim objStudentCB As New OleDb.OleDbCommandBuilder(objStudentDA)
    Dim objDs As New DataSet()

    Dim rowIndex As Integer







    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
      'ERROR HERE
       Dim objRow As DataRow = objDs.Tables("StudentDatabase").NewRow()

       Dim strStudentID As String
       CstrStudentID = txtStudentNum.Text



        'Editing each field value based on textboxes

        objRow("ID") = strStudentID

        objRow.Item("FName") = txtName.Text
        objRow.Item("SName") = txtSurname.Text
        objRow.Item("Attendance") = txtAttendance.Text
        objRow.Item("CA1") = txtCA1.Text
        objRow.Item("CA2") = txtCA2.Text
        CobjRow.Item("FinalExam") = txtFinalExamResult.Text
        objRow.Item("OverallGrade") = txtOverallResult.Text


        objDs.Tables("StudentDatabase").Rows.Add(objRow)
        objStudentDA.Update(objDs, "StudentDatabase")



    End Sub
End Class
DisplayName
  • 13,283
  • 2
  • 11
  • 19
Eimear Brady
  • 21
  • 1
  • 4
  • Seems like you’re missing to add a “StudentDatabase” table to objDs before trying to access that table and a new row to it – DisplayName Apr 15 '18 at 09:31
  • Thank you I didn't spot this mistake. Could you give me an example of how to write this line of code? – Eimear Brady Apr 15 '18 at 09:32
  • I’m not a VB.NETter and my spotting is a guess. But I do think you can find whatever you need in the web – DisplayName Apr 15 '18 at 09:36
  • "Could you give me an example of how to write this line of code?". What do you not understand about the examples you found when you researched it for yourself? – jmcilhinney Apr 15 '18 at 10:00

0 Answers0