locked
object not set to an instance RRS feed

  • Question

  • User1717218719 posted

    I have the following code which aims to add data entered in the table to the repeater below. currently, the code I have I recieve an error "object not set to an instance" on line drwRow("RelatedDoc") = str1. I am unsure as to why this is happening any helpwould be great.

    Friday, June 28, 2019 12:25 PM

Answers

  • User409696431 posted

    The code you have:

            If Not IsNothing(drwRow) Then
                '-- already in datatable
    
                MsgBox("Already in DataTable")
                Exit Sub
    
            Else
    
                drwRow("RelDoc") = str1
                dtbReldoc.Rows.Add(drwRow)
    
            End If

    is trying to assign a value to a row that is already "Nothing", and it does not have the schema of the datatable.

    Create a new row for that datatable, and assign the value there.  Try something like:

    ,,,
    
    Else
    
    Dim R As DataRow = dtbReldoc.NewRow
    R("RelDoc") = str1
    dtbReldoc.Rows.Add(R)
    
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 28, 2019 8:57 PM

All replies

  • User409696431 posted

    The code you have:

            If Not IsNothing(drwRow) Then
                '-- already in datatable
    
                MsgBox("Already in DataTable")
                Exit Sub
    
            Else
    
                drwRow("RelDoc") = str1
                dtbReldoc.Rows.Add(drwRow)
    
            End If

    is trying to assign a value to a row that is already "Nothing", and it does not have the schema of the datatable.

    Create a new row for that datatable, and assign the value there.  Try something like:

    ,,,
    
    Else
    
    Dim R As DataRow = dtbReldoc.NewRow
    R("RelDoc") = str1
    dtbReldoc.Rows.Add(R)
    
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 28, 2019 8:57 PM
  • User1717218719 posted

    I actually got it working using the following code. thanks for your help

          '-- Get all items in labels in repeater
            dtbReldoc = GetRelatedDocItms()
    
            '-- Add new item
            '-- check if item is already in the datable
            Dim str1 As String = txtbox.Text
    
            drwRow = dtbReldoc.Rows.Find(str1)
    
            If Not IsNothing(drwRow) Then
                '-- already in datatable
    
                drwRow("RelDoc") = str1
    
              
                Exit Sub
    
            Else
    
                drwRow = dtbReldoc.NewRow()
    
                drwRow("RelDoc") = str1
    
                dtbReldoc.Rows.Add(drwRow)
    
            End If
    
            '--Bind
            Me.RptRelDoc.DataSource = dtbReldoc
            Me.RptRelDoc.DataBind()

    Monday, July 1, 2019 10:24 AM