Tengo un problema. Estoy intentando que el siguiente codigo actualize un registro en una tabla de MYSQL y todo funciona perfectamente a EXCEPCION del campo "perfil" que siempre que el programa entra dentro del metodo de update (UpdateMethod="saveUser") tiene valor de cero.
Creo que no estoy ligando bien el update parameter de perfil con el DropDownList que corresponde tambien a perfil.
Tengo 2 tablas: 1 para "User" y otra para "perfil" (esta ultima no la actualizo, solo la uso para llenar el DropDownList.
Les agradezco mucho su ayuda.
Un beso.
Codigo aspx:
Código:
<asp:GridView id="UserGridView" DataSourceID="ObjetDataUserGridView" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateColumns="False" SelectedDataKey="perfil" DataKeyNames="Id" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" AllowPaging="True" onrowupdated="updated" onrowupdating="updating" > <FooterStyle BackColor="#CCCCCC" ForeColor="Black" /> <RowStyle BackColor="#EEEEEE" ForeColor="Black" /> <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="#DCDCDC" /> <PagerSettings FirstPageText="<<" LastPageText=">>" NextPageText=">" PreviousPageText="<" Mode="NextPreviousFirstLast" /> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" /> <asp:BoundField DataField="Nombre" HeaderText="Nombre" SortExpression="Nombre" /> <asp:BoundField DataField="Login" HeaderText="Login" SortExpression="Login" /> <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" /> <asp:TemplateField HeaderText="Perfil" > <EditItemTemplate> <asp:DropDownList id="ddlPerfil" runat="server" Width="120px" DataSourceID="SqlDataSourcePerfil" DataTextField="perfil" DataValueField="perfilid" AutoPostBack="false" SelectedValue='<%# Bind("perfil") %>'> </asp:DropDownList> <asp:SqlDataSource id="SqlDataSourcePerfil" runat="server" ConnectionString="<%$ ConnectionStrings:stringConnection %>" ProviderName="MySql.Data.MySqlClient" SelectCommand="select perfilid, perfil from perfil"> </asp:SqlDataSource> </EditItemTemplate> <ItemTemplate> <asp:Label id="LabelPerfil" runat="server" Text='<%# Eval("Perfil") %>' Width="136px"></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> <asp:BoundField DataField="FechaCreacion" HeaderText="FechaCreacion" SortExpression="FechaCreacion" ReadOnly="True" /> <asp:BoundField DataField="FechaModificacion" HeaderText="FechaModificacion" SortExpression="FechaModificacion" ReadOnly="True" /> </Columns> </asp:GridView> <asp:ObjectDataSource runat="server" id="ObjetDataUserGridView" SelectMethod="GetAllUsers" UpdateMethod="saveUser" DeleteMethod="deleteUser" DataObjectTypeName="com.sis.telecabletepa.catalogos.User" TypeName="com.sis.telecabletepa.catalogos.UserManager" onupdated="modificarPerfil_updated" onupdating="modificarPerfil_updating"> <UpdateParameters> <asp:Parameter Name="Id" Type="Int16" /> <asp:Parameter Name="Nombre" Type="String" /> <asp:Parameter Name="Login" Type="String" /> <asp:Parameter Name="Password" Type="String" /> <asp:ControlParameter ControlID="ddlPerfil" Name="Perfil" PropertyName="SelectedValue" Type="Int16" /> <asp:Parameter Name="Email" Type="String" /> <asp:Parameter Name="FechaCreacion" Type="DateTime" /> <asp:Parameter Name="FechaModificacion" Type="DateTime" /> </UpdateParameters> </asp:ObjectDataSource>
Clase User:
Código:
metodo de update:public class User { public User() { // // TODO: Add constructor logic here // } //Variables private int id; private string nombre; private string login; private string password; private int perfil; private string email; private DateTime fechacreacion; private DateTime fechamodificacion; private int estado; public int Id { set { id = value; } get { return id; } } public string Nombre { set { nombre = value; } get { return nombre; } } public string Login { set { login = value; } get { return login; } } public string Password { set { password = value; } get { return password; } } public int Perfil { set { perfil = value; } get { return perfil; } } public string Email { set { email = value; } get { return email; } } public DateTime Fechacreacion { set { fechacreacion = value; } get { return fechacreacion; } } public DateTime Fechamodificacion { set { fechamodificacion = value; } get { return fechamodificacion; } } public int Estado { set { estado = value; } get { return estado; } } }
Código:
public static void saveUser(User user) { DateTime MyDateTime = DateTime.Now; string sqlCmd = null; sqlCmd = "update usuario "; sqlCmd += "set "; sqlCmd += "nombre = '" + user.Nombre + "', login = '" + user.Login + "', password = '" + user.Password + "', perfilid = " + user.Perfil + ", email = '" + user.Email + "', fechamodificacion = '" + MyDateTime.ToString("yyyy/MM/dd") + "' where usuarioid = " + user.Id; DataBaseConnection.modifySQLCommand(sqlCmd); }