Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the code to update the perticular field of the gridview
VB
Protected Sub UpdateTDetails(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
      Try


      Dim LblID As Integer = DirectCast(GridViewTDetalis.Rows(e.RowIndex).FindControl("lblID"), Label).Text
      Dim txtfuncobj As String = DirectCast(GridViewTDetalis.FooterRow.FindControl("txtfuncobj0"), TextBox).Text
      Dim txtmeasuredvar As String = DirectCast(GridViewTDetalis.FooterRow.FindControl("txtmeasuredvar0"), TextBox).Text
      Dim txtdeadline As String = DirectCast(GridViewTDetalis.FooterRow.FindControl("txtdeadline0"), TextBox).Text
      Dim txtweight_fact As String = DirectCast(GridViewTDetalis.FooterRow.FindControl("txtweight_fact0"), TextBox).Text

      Dim con As New SqlConnection(strConnString)
      Dim cmd As New SqlCommand()
      cmd.CommandType = CommandType.Text
      cmd.CommandText = "update MBO_Details set MBO_FUNC_OBJ=@func_obj,MBO_MEASURED_VAR=@mesrd_var,MBO_DEADLINE=@tar_dt,MBO_WEIGHT_FACT=@wt_fact where id=@idnum;" _
      & "select id, MBO_EMP_CODE,MBO_FUNC_OBJ, MBO_MEASURED_VAR, MBO_DEADLINE,MBO_WEIGHT_FACT from MBO_Details where MBO_EMP_CODE='40000001'" 'where emp_no='" & (EMP_NO) & "' and trid is null  order by id"

      cmd.Parameters.Add("@idnum", SqlDbType.VarChar).Value = LblID
      cmd.Parameters.Add("@func_obj", SqlDbType.VarChar).Value = txtfuncobj
      cmd.Parameters.Add("@mesrd_var", SqlDbType.VarChar).Value = txtmeasuredvar
      cmd.Parameters.Add("@tar_dt", SqlDbType.VarChar).Value = txtdeadline
      cmd.Parameters.Add("@wt_fact", SqlDbType.VarChar).Value = txtweight_fact

      GridViewTDetalis.EditIndex = -1
      GridViewTDetalis.DataSource = GetDataTDetails(cmd)
          GridViewTDetalis.DataBind()
      Catch ex As Exception
          MsgBox(ex.Message)
      End Try
  End Sub



but gets the error message
"Object reference not set to an instance of an object."
what will the problem ?
Posted
Comments
Kornfeld Eliyahu Peter 25-Feb-14 2:40am    
At which line the error is?
Artefakt94 25-Feb-14 4:18am    
Debug your code to find error's line ...
Ni!E$H_WAGH 25-Feb-14 6:02am    
I solved it.I have used FooterRow in place of e.rowIndex

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