【发布时间】:2016-06-25 14:44:19
【问题描述】:
我的 html 中有这个:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand = "GridView1_RowCommand"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
SortExpression="CustomerID" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
SortExpression="ProductID" />
<asp:BoundField DataField="TotalProduct" HeaderText="TotalProduct"
SortExpression="TotalProduct" />
<asp:BoundField DataField="UpdatedProduct" HeaderText="UpdatedProduct" SortExpression="UpdatedProduct" />
<asp:BoundField DataField="ProductQuantity" HeaderText="ProductQuantity" SortExpression="ProductQuantity" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnApprove" runat="server" Text="Approve" CommandName="Approve" CommandArgument='<%# Eval("ProductID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Myconn %>"
SelectCommand="SELECT CustomerProducts.*, Products.ProductQuantity FROM CustomerProducts INNER JOIN Products ON CustomerProducts.ProductID = Products.ProductID">
</asp:SqlDataSource>
下面是代码:
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 ProductID=@ProductID", scn);
cmd.Parameters.AddWithValue("@ProductID", ID);
cmd.ExecuteNonQuery();
}
}
}
我真的不知道我遇到了什么错误。我在这里尝试做的是点击链接,它将更新updatedproduct 列。
这是截图
更新:
我收到此错误:
将 nvarchar 值“__Page”转换为数据类型 int 时转换失败。
【问题讨论】:
-
8 小时 5 个问题,所有这些都是真正的基本 sql 概念。请学习sql教程。这不是一个教程网站。而且您使用的是 Microsoft SQL Server,而不是我们在昨晚之后知道的 mysql。
标签: c# asp.net sql-server gridview asplinkbutton