按钮单击不借口SQL查询
我正在开发一个小型网站,以帮助我去的本地健身房。
我能够列出特定客户的所有发票,并添加一个按钮以确认已付款时已付款,
但是当我按该按钮时,代码中的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
//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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论