Ver Mensaje Individual
  #5 (permalink)  
Antiguo 15/03/2005, 07:06
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 20 años, 3 meses
Puntos: 1
Hola bueno intente arreglar el problema asi
parq que en modo edicion tome la selccion de los combos y la guarde

lo hice asi
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 CodigoID = @CodigoID, 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 10
Dim CurrentTextBox As TextBox
CurrentTextBox = E.Item.FindControl("edit_" & Cols(I))
Dim ColValue As String = CurrentTextBox.Text
MyCommand.Parameters("@" & Cols(I)).Value = ColValue

Next

Dim StateDropDownList As DropDownList
StateDropDownList = E.Item.FindControl("DropDownList1")
MyCommand.Parameters("@Estado").Value = StateDropDownList.SelectedItem.ToString()

Dim CityDropDownList As DropDownList
CityDropDownList = E.Item.FindControl("DropDownList2")
MyCommand.Parameters("@Ciudad").Value = CityDropDownList.SelectedItem.ToString()

Dim UbiDropDownList As DropDownList
UbiDropDownList = E.Item.FindControl("DropDownList3")
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"
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

Guiando por supuesto del manual
pero sabes estoy completamente segura que lo hice mal, la embarre

me da 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 117: Dim ColValue As String = CurrentTextBox.Text


y no entiendo porque esta mal