I have an sql datasource inner joined with 2 tables (product table[product quantity column]
and customer product table[ProductID,CustomerID,TotalProducts, UpdatedProducts])
Currently i have this code behind using a sql button:
using (SqlConnection scn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True"))
{
scn.Open();
SqlCommand cmd = new SqlCommand("update o set o.Updatedproduct = p.ProductQuantity - o.Totalproduct from CustomerProducts o inner join Products p on o.ProductID = p.ProductID", scn);
cmd.ExecuteNonQuery();
}
though it works fine and upon button click, it updates all the fields in the updated products column
but what i want to do is to do the same functionality but with a hyperlink. Also, it will only update a specific field. Here is an image to make it clearer:
UPDATE:
so far i got this.
html:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnApprove" runat="server" Text="Approve" CommandName="UpdateProduct" CommandArgument='<%#Eval("CustomerID")+","+ Eval("ProductID") %>' />
</ItemTemplate>
</asp:TemplateField>
code behind:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Approve")
{
using (SqlConnection scn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True"))
{
scn.Open();
SqlCommand cmd = new SqlCommand("update o set o.Updatedproduct = p.ProductQuantity - o.Totalproduct from CustomerProducts o inner join Products p on o.ProductID = p.ProductID WHERE WHERE ProductID=@ProductID", scn);
cmd.Parameters.AddWithValue("@ProductID", ID);
cmd.ExecuteNonQuery();
}
}
}
nothings happening here
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…