按钮单击不借口SQL查询

发布于 2025-02-09 07:09:22 字数 1732 浏览 0 评论 0原文

我正在开发一个小型网站,以帮助我去的本地健身房。

我能够列出特定客户的所有发票,并添加一个按钮以确认已付款时已付款,

但是当我按该按钮时,代码中的SQL查询不会被执行。我怀疑它是因为每次点击该按钮时,页面都在重新加载,但我不确定。 另外,如果我只有一个客户在下拉列表中的工作正常工作,所以我知道问题不是SQL查询

“在此处输入图像说明”

                //Ajout Bouton Modifier/Ajouter
                Button bouton = new Button();
                bouton.ID = "bouton" + i.ToString();
                TableCell ajoutbouton1 = new TableCell();

                bouton.Text = "Paiement reçu";

                bouton.Attributes["idfacture"] = numfactures;
                bouton.Click += new EventHandler(this.bouton_Click);
                ajoutbouton1.Attributes.Add("onclick", "return confirm('confirmez votre sélection?');");

                ajoutbouton1.Controls.Add(bouton);
                tRow1.Cells.Add(ajoutbouton1);
                ajoutbouton1.Width = 80;

                ajoutbouton1.HorizontalAlign = HorizontalAlign.Center;

protected void bouton_Click(object sender, EventArgs e)
{
    Button bouton = (Button)sender;
    string idfacture = (string)(bouton.Attributes["idfacture"]);
    string idclient = DropDownList1.SelectedValue;

    SqlConnection con = new SqlConnection("Server=localhost\\MSSQLSERVER01;Database=GYMDB;Trusted_Connection=True;");
    DataTable dt4 = new DataTable();
    con.Open();
    SqlCommand GetIdFonction = new SqlCommand("UPDATE [dbo].[Finance] SET [status] = 1 WHERE idfacture = " + idfacture + "", con);
    SqlDataReader dr4 = GetIdFonction.ExecuteReader();
    con.Close();
    Populerliste(Int32.Parse(idclient));
}

Im developping a small website to help a local gym I go to.

Im able to list all of the invoices for a specific customer and add a button to confirm that an invoice has been paid

However when i press that button the sql query in code behind is not being executed. I suspect its because the page is reloading everytime I click on that button but im not sure.
Also if i only have one customer in the dropdownlist its working fine, so i know that the problem is not the sql query

enter image description here

                //Ajout Bouton Modifier/Ajouter
                Button bouton = new Button();
                bouton.ID = "bouton" + i.ToString();
                TableCell ajoutbouton1 = new TableCell();

                bouton.Text = "Paiement reçu";

                bouton.Attributes["idfacture"] = numfactures;
                bouton.Click += new EventHandler(this.bouton_Click);
                ajoutbouton1.Attributes.Add("onclick", "return confirm('confirmez votre sélection?');");

                ajoutbouton1.Controls.Add(bouton);
                tRow1.Cells.Add(ajoutbouton1);
                ajoutbouton1.Width = 80;

                ajoutbouton1.HorizontalAlign = HorizontalAlign.Center;

protected void bouton_Click(object sender, EventArgs e)
{
    Button bouton = (Button)sender;
    string idfacture = (string)(bouton.Attributes["idfacture"]);
    string idclient = DropDownList1.SelectedValue;

    SqlConnection con = new SqlConnection("Server=localhost\\MSSQLSERVER01;Database=GYMDB;Trusted_Connection=True;");
    DataTable dt4 = new DataTable();
    con.Open();
    SqlCommand GetIdFonction = new SqlCommand("UPDATE [dbo].[Finance] SET [status] = 1 WHERE idfacture = " + idfacture + "", con);
    SqlDataReader dr4 = GetIdFonction.ExecuteReader();
    con.Close();
    Populerliste(Int32.Parse(idclient));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文