Hi,

I keep getting the error:

Object reference not set to an instance of an object.

When attempting to check if a database record is Null or not using the line:

If IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(8)) = True Then
            addsub2()
        End If

I'm sure that I have opened and closed the database correctly, so I'm not sure what excactly the problem is.

Any Ideas?

Thanks In Advance.

please post your full code , so that we can help you.

Dim connection As New OleDb.OleDbConnection
    Dim Provider As String = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;"
    Dim Source As String = "Data Source = F:\My Documents\Computing\COMP4 CW\WND.accdb"
    Dim dSet As New DataSet
    Dim dAdapter As New OleDb.OleDbDataAdapter
    Dim incr As Integer = -1
    Dim maxRows As Integer
    Dim arrayLines() As String
    Dim record As String
    Dim command As OleDb.OleDbCommand
    Dim updateCommand As String
    Dim formSubscriptions As New formSubscriptions
    Dim boxUsed As Boolean = False
    Public subNo As Integer = 1

    Public Sub btnAddSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSub.Click

        record = comboSubs.Text
        arrayLines = record.Split(" ")

        connection.ConnectionString = Provider & Source
        connection.Open()

        If IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(8)) = True Then
            addsub2()
        ElseIf IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(11)) = True Then
            addsub2()
        ElseIf IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(14)) = True Then
            addsub2()
        ElseIf IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(17)) = True Then
            addsub2()
        ElseIf IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(20)) = True Then
            addsub2()
        ElseIf IsDBNull(dSet.Tables("Subscriptions").Rows(incr).Item(23)) = True Then
            addsub2()
        Else
            MsgBox("All records are full.")
        End If

addsub2:

f arrayLines.Length = 3 Then
            record = comboSubs.Text
            arrayLines = record.Split(" ")

            updateCommand = "UPDATE Subscriptions SET Subscriptions.[PMID " & subNo & "] = '" & arrayLines(0).ToString _
            & "',Subscriptions.[PMName " & subNo & "] = '" & arrayLines(1).ToString _
            & "',Subscriptions.[Price " & subNo & "] = '" & arrayLines(2).ToString _
            & "'WHERE Subscriptions.[Customer ID] = '" & txtCustomerID.Text & "'"


            command = New OleDb.OleDbCommand(updateCommand, connection)
            command.ExecuteNonQuery()
            command.Dispose()

        ElseIf arrayLines.Length = 4 Then
            updateCommand = "UPDATE Subscriptions SET Subscriptions.[PMID " & subNo & "] = '" & arrayLines(0).ToString _
            & "',Subscriptions.[PMName " & subNo & "] = '" & arrayLines(1).ToString & " " _
                                               & arrayLines(2).ToString _
            & "',Subscriptions.[Price " & subNo & "] = '" & arrayLines(3).ToString _
            & "'WHERE Subscriptions.[Customer ID] = '" & txtCustomerID.Text & "'"

            command = New OleDb.OleDbCommand(updateCommand, connection)
            command.ExecuteNonQuery()
            command.Dispose()

        ElseIf arrayLines.Length = 5 Then
            updateCommand = "UPDATE Subscriptions SET Subscriptions.[PMID " & subNo & "] = '" & arrayLines(0).ToString _
                        & "',Subscriptions.[PMName " & subNo & "] = '" & arrayLines(1).ToString & " " _
                        & arrayLines(2).ToString & " " _
                        & arrayLines(3).ToString() _
                        & "',Subscriptions.[Price " & subNo & "] = '" & arrayLines(4).ToString _
                        & "'WHERE Subscriptions.[Customer ID] = '" & txtCustomerID.Text & "'"


            command = New OleDb.OleDbCommand(updateCommand, connection)
            command.ExecuteNonQuery()
            command.Dispose()

        Else
            MsgBox("The name is too long. Please shorten it to a maximum of 3 words.", MsgBoxStyle.Critical)
        End If

        connection.Close()
    End Sub

just change this

Dim command As OleDb.OleDbCommand
'with this
 Dim command As new OleDb.OleDbCommand

Hope this will solve your prob :)

Regards

Still no luck, same error :(

Here try : the incr variable is set to as -1 of course no value such as -1 in ms access you need to be set it at 0 just try. Hope it works

No luck either,,,

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.