1

Estoy tratando de realizer un Update a los registros que tengo en mi base de datos en Access al principio funcionaba y cambiaba todos los registros por que no tenia un id = id, despues lo coloque en el Query pero ya no funciona nada, no hace ningun Update

este es mi codigo:

string myConnectionString = @"C:\\Users\\gutiece\\Desktop\\database\\" + "Database1.accdb";

             using (OleDbConnection connection = new OleDbConnection())
             {
                 using (OleDbCommand command = new OleDbCommand())
                 {
                     connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
                     command.Connection = connection;
                     connection.Open();

                     command.Parameters.AddWithValue("@ID", Convert.ToInt32(Txt_id.Text));
                     command.Parameters.AddWithValue("@STATUS", Dpo_status.Text.Trim());
                     command.Parameters.AddWithValue("@AREA", Dpo_buckets.Text.Trim());
                     command.Parameters.AddWithValue("@TOOL", Txt_tool.Text.Trim());
                     command.Parameters.AddWithValue("@RESPONSABLE", Txt_resp.Text.Trim());
                     command.Parameters.AddWithValue("@NOTA", Txt_notas.Text.Trim());
                     command.Parameters.AddWithValue("@REPAIR", Txt_dates.Text.Trim());

                     command.CommandText = "UPDATE status_change SET status = @STATUS, area = @AREA, tool = @TOOL, responsable = @RESPONSABLE, nota = @NOTA, repair = @REPAIR, repare = 1 WHERE id = @ID";

                     command.ExecuteNonQuery();
                     Response.Redirect("dashboard.aspx");
                     connection.Close();
                 }
             }

y este es el codigo del Panel:

<asp:Panel ID="PanelEdit" runat="server" CssClass="panel panel-primary" Width="750px" Style="display: none">
        <asp:Panel ID="panelEditTitle" runat="server" CssClass="panel-heading">
            <h3 align="center"><span><i class="fa fa-reply" aria-hidden="true">&nbsp Re-Assign Tool</i></span></h3>
        </asp:Panel>
        <div class="panel-body">
            <div align="center">
                <div class="input-group col-xs-9" style="display: none">
                    <span class="input-group-addon">id</span>
                    <asp:TextBox ID="Txt_id" runat="server" class="form-control" AutoComplete="off" Enabled="False"></asp:TextBox>
                </div>
                &nbsp
                    <div class="input-group col-xs-9">
                        <span class="input-group-addon">Responsable</span>
                        <asp:TextBox runat="server" type="text" ID="Txt_resp" class="form-control" ReadOnly="true"></asp:TextBox>
                    </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Txt_resp" Display="None" ErrorMessage="You miss a responsable" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
                            <div class="input-group col-xs-9">
                                <span class="input-group-addon">Area</span>
                                <asp:DropDownList ID="Dpo_buckets" CssClass="form-control" runat="server" Enabled="False">
                                            <asp:ListItem>MCH</asp:ListItem>
                                        </asp:DropDownList>
                            </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Txt_tool" Display="None" ErrorMessage="You miss the tool" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
                            <div class="input-group col-xs-9">
                                <span class="input-group-addon">Tool</span>
                                <asp:TextBox runat="server" type="text" ID="Txt_tool" class="form-control" ReadOnly="true" />
                            </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="Txt_tool" Display="None" ErrorMessage="You miss the tool" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
                            <div class="input-group col-xs-9">
                                <span class="input-group-addon">Status</span>
                                <asp:DropDownList ID="Dpo_status" CssClass="form-control" runat="server" Enabled="False">
                                </asp:DropDownList>
                            </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Dpo_status" Display="None" ErrorMessage="Select a status" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
                            <div class="input-group col-xs-9">
                                <span class="input-group-addon">Nota</span>
                                <asp:TextBox ID="Txt_notas" runat="server" type="text" class="form-control"/>
                            </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="Txt_notas" Display="None" ErrorMessage="You need to assign a note" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
                            <div class="input-group col-xs-9">
                                <span class="input-group-addon">Date</span>
                                <asp:TextBox ID="Txt_dates" runat="server" type="text" class="form-control" ReadOnly="true"/>
                            </div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="Txt_dates" Display="None" ErrorMessage="Select the current date" ValidationGroup="edit"></asp:RequiredFieldValidator>
                &nbsp
            <div class="panel-footer">
                <asp:Button ID="SubmitBT" runat="server" Text="Submit" CssClass="btn btn-primary" ValidationGroup="edit" OnClick="SubmitBT_Click" />
                <asp:Button ID="DismissBT" runat="server" Text="Dismiss" CssClass="btn btn-primary" CausesValidation="false" />
            </div>
            </div>
        </div>
    </asp:Panel>
4
  • Y hay algun Id como el que estas mandando?
    – gbianchi
    Commented el 5 jun. 2017 a las 18:24
  • claro, todo lo traigo de la base de datos, hago un BrackPoint y si tiene el valor del id correspondiente del registro que quiero editar Commented el 5 jun. 2017 a las 18:30
  • 1
    y ese update directamente en la bd si funciona???
    – gbianchi
    Commented el 5 jun. 2017 a las 18:46
  • Efectivamente pero ya lo solucione, ponder mi respuesta, Gracias por tomarte tu tiempo!! Commented el 5 jun. 2017 a las 18:50

1 respuesta 1

0
protected void SubmitBT_Click(object sender, EventArgs e)
        {
             string myConnectionString = @"C:\\Users\\gutiece\\Desktop\\database\\" + "Database1.accdb";

             using (OleDbConnection connection = new OleDbConnection())
             {
                 using (OleDbCommand command = new OleDbCommand())
                 {
                     connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
                     command.Connection = connection;
                     connection.Open();

                     int id = Convert.ToInt32((Txt_id.Text));
                     command.Parameters.AddWithValue("@STATUS", Dpo_status.Text.Trim());
                     command.Parameters.AddWithValue("@AREA", Dpo_buckets.Text.Trim());
                     command.Parameters.AddWithValue("@TOOL", Txt_tool.Text.Trim());
                     command.Parameters.AddWithValue("@RESPONSABLE", Txt_resp.Text.Trim());
                     command.Parameters.AddWithValue("@NOTA", Txt_notas.Text.Trim());
                     command.Parameters.AddWithValue("@REPAIR", Txt_dates.Text.Trim());

                     command.CommandText = "UPDATE status_change SET status = @STATUS, area = @AREA, tool = @TOOL, responsable = @RESPONSABLE, nota = @NOTA, repair = @REPAIR, repare = 1 WHERE id = @ID";

                     command.Parameters.Add("@ID", OleDbType.Integer).Value = id;

                     command.ExecuteNonQuery();
                     Response.Redirect("dashboard.aspx");
                     connection.Close();
                 }
             }
        }

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.