hola tengo un datagrid que cuando le doy actualizar en modo diseño me genra este error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 273: Dim ColValue As String
Line 274: ColValue = CurrentTextBox.Text
el codigo completo de actualizacion es este
Sub MyDataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
If (Page.IsValid)
Dim DS As DataSet
Dim MyCommand As SqlCommand
Dim UpdateCmd As String = "UPDATE Agencia SET Agencia = @Agencia, Direccion = @Direccion, Codigo_Area = @Codigo_Area, Telefono = @Telefono, Fax = @Fax, Estado = @Estado, Ciudad = @Ciudad, Ubicacion = @Ubicacion,Estacionamiento= @Estacionamiento, Cajero_Automatico= @Cajero_Automatico, Autobanco= @Autobanco,Taquilla_Externa= @Taquilla_Externa, WHERE CodigoID = @CodigoID"
MyCommand = New SqlCommand(UpdateCmd, MyConnection)
MyCommand.Parameters.Add(New SqlParameter("@CodigoID", SqlDbType.NVarChar, 11))
MyCommand.Parameters.Add(New SqlParameter("@Agencia", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Direccion", SqlDbType.NVarChar, 20))
MyCommand.Parameters.Add(New SqlParameter("@Codigo_Area", SqlDbType.NChar, 12))
MyCommand.Parameters.Add(New SqlParameter("@Telefono", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Fax", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Estado", SqlDbType.NVarChar, 20))
MyCommand.Parameters.Add(New SqlParameter("@Ciudad", SqlDbType.NChar, 2))
MyCommand.Parameters.Add(New SqlParameter("@Ubicacion", SqlDbType.NChar, 5))
MyCommand.Parameters.Add(New SqlParameter("@Estacionamiento", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Cajero_Automatico", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Autobanco", SqlDbType.NVarChar,1))
MyCommand.Parameters.Add(New SqlParameter("@Taquilla_Externa", SqlDbType.NVarChar,1))
MyCommand.Parameters("@CodigoID").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
Dim Cols As String() = {"Agencia","Direccion","Codigo_Area","Telefono","F ax", "Estacionamiento", "Cajero_Automatico", "Autobanco", "Taquilla_Externa"}
Dim I As Integer
For I = 0 To 8
Dim CurrentTextBox As TextBox
CurrentTextBox = E.Item.FindControl("edit_" & Cols(I))
Dim ColValue As String
ColValue = CurrentTextBox.Text
MyCommand.Parameters("@" & Cols(I)).Value = ColValue
Next
Dim StateDropDownList As DropDownList
StateDropDownList = E.Item.FindControl("DropDownList4")
MyCommand.Parameters("@Estado").Value = StateDropDownList.SelectedItem.ToString()
Dim CityDropDownList As DropDownList
CityDropDownList = E.Item.FindControl("DropDownList5")
MyCommand.Parameters("@Ciudad").Value = CityDropDownList.SelectedItem.ToString()
Dim UbiDropDownList As DropDownList
UbiDropDownList = E.Item.FindControl("DropDownList6")
MyCommand.Parameters("@Ubicacion").Value = UbiDropDownList.SelectedItem.ToString()
MyCommand.Connection.Open()
Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>Registro actualizado</b><br>" & UpdateCmd
MyDataGrid.EditItemIndex = -1
Catch Exp As SqlException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: ya existe un registro con la misma clave principal"
Else
Message.InnerHtml = "ERROR: no se pudo actualizar el registro, compruebe que los campos están rellenos correctamente" &Exp.Message
End If
Message.Style("color") = "red"
End Try
MyCommand.Connection.Close()
BindGrid()
Else
Message.InnerHtml = "ERROR: compruebe las condiciones de error de cada campo."
Message.Style("color") = "red"
End If
End Sub
gracias por la ayuda