SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding a row in a dataset

    I am trying to find a row in a datagrid to update my dataset but i keep getting the following error:
    System.NullReferenceException: Object reference not set to an instance of an object.

    Here is my code, the bold line is the line with the error:
    Sub dgMembers_Update(s As Object, e As DataGridCommandEventArgs)
    If Page.IsValid
    Try
    trace.write(dgMembers.DataKeys(e.Item.ItemIndex))
    Dim objDR = objDS.Tables("tblMembers").DefaultView.Find(dgMembers.DataKeys(e.Item.ItemIndex)) objDR("Firstname") = CType(e.Item.FindControl("txtFirstname"), TextBox).Text
    objDR("Lastname") = CType(e.Item.FindControl("txtLastname"), TextBox).Text
    objDR("Email") = CType(e.Item.FindControl("txtEmail"), TextBox).Text
    objDR("IsAdmin") = IIf(CType(e.Item.FindControl("ddlAdmin"), DropDownList).SelectedItem.Value = "1", true, false)
    objDR("IsAdmin") = IIf(CType(e.Item.FindControl("ddlBanned"), DropDownList).SelectedItem.Value = "1", true, false)
    ' Update the dataset and database
    objCB = New OleDbCommandBuilder(objDA)
    objDA.Update(objDS, "tblMembers")
    Catch objOleDbException As OleDbException
    lblError.Text = "<p>" & objOleDbException.ErrorCode & "</p>"
    lblError.Text += "<p>" & objOleDbException.Message & "</p>"
    lblError.Text += "<p>" & objOleDbException.StackTrace & "</p>"
    lblError.Visible = true
    End Try

    dgMembers.EditItemIndex = -1
    BindData()
    End If
    End Sub

  2. #2
    SitePoint Enthusiast Nawaz Ijaz's Avatar
    Join Date
    Feb 2005
    Location
    Lahore, Pakistan
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the error message tell any row number ?
    This error normally occur when u just take a reference and donot assign memory by calling constructor using New Operator.

    Don't know where is the error, just check wether "objDA" has been assigned the memory.

    objDA.Update(objDS, "tblMembers")
    Nawaz Ijaz [Lahore, Pakistan]
    Boy: He is big..i wont like to fight him...
    Achilles: Thatz Y no one wud remember u after thousand years...!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •