Tema: error
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/03/2005, 13:35
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 6 meses
Puntos: 1
error

Hola tengo un error en modo edicion cuando pulso actualizar
ERROR: no se pudo actualizar el registro, compruebe que los campos estn rellenos correctamenteEl nombre de columna 'Estado' no es válido.


Pero no veo ni entiendo porque dice que no es valido

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 Ciudad SET Nombre_Ciudad = @Nombre_Ciudad, Estado = @Estado Where CiudadID= @CiudadID"

MyCommand = New SqlCommand(UpdateCmd, MyConnection)

MyCommand.Parameters.Add(New SqlParameter("@CiudadID", SqlDbType.NVarChar, 11))
MyCommand.Parameters.Add(New SqlParameter("@Nombre_Ciudad", SqlDbType.NVarChar, 40))
MyCommand.Parameters.Add(New SqlParameter("@Estado", SqlDbType.NVarChar, 40))

MyCommand.Parameters("@CiudadID").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))

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

Dim CityDropDownList As DropDownList
CityDropDownList = E.Item.FindControl("DropDownList2")
MyCommand.Parameters("@Estado").Value = CityDropDownList.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

Sub BindGrid()

Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim strSql As String = "Select Ciudad.CiudadID as CiudadID, Ciudad.Nombre_Ciudad as Nombre_Ciudad, Estado.Nombre_Estado as Estado from Ciudad, Estado where Ciudad.EstadoID = Estado.EstadoID"

MyCommand = new SqlDataAdapter(strSql, MyConnection)


DS = new DataSet()
MyCommand.Fill(DS, "Ciudad")

MyDataGrid.DataSource=DS.Tables("Ciudad").DefaultV iew
MyDataGrid.DataBind()
End Sub


en el grid lo coloco asi

<asp:TemplateColumn SortExpression="Estado" HeaderText="Estado">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Estado") %>' ID="Label2" NAME="Label6"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList autopostback ="True" runat="server" id="Dropdownlist2" DataSource='<%# Estado () %>' DataValueField="EstadoID" DataTextField="Nombre_Estado">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

Gracias por la ayuda de antemano