Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i wrote the below code to delete a record from a gridview but i am getting error 'Object reference not set to an instance of an object.' in the parameter for selecting grid value. please advice

VB
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting


       Dim Parram(6) As Object


       Parram(0) = TxtTrx.Text.Trim
       Parram(1) = GridView1.SelectedRow.Cells(1).Text
       Parram(2) = GridView1.SelectedRow.Cells(2).Text
       Parram(3) = GridView1.SelectedRow.Cells(3).Text
       Parram(4) = GridView1.SelectedRow.Cells(3).Text
       Parram(5) = GridView1.SelectedRow.Cells(4).Text




       Dim Count As Integer = DataBase.ExecuteNonQuery("sp_DeletePTY_Rmt_D", Parram, "Aloha2GP")
       If Count > 0 Then
           LblError.Text = "(" & Count & ")" & "Record Deleted"
       Else

           LblError.Text = "(" & Count & ")" & " Record Deleted"
       End If

end sub
Posted

1 solution

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line (Here: parameter for selecting grid value). Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900