2016-06-25 15 views
-2

に「商品コード」:あいまいな列名は、私は私のhtmlでこれを持ってasp.net

<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 [email protected]", scn); 
       cmd.Parameters.AddWithValue("@ProductID", ID); 
       cmd.ExecuteNonQuery(); 
      } 
     } 
    } 

私は本当に何のアイデアを持っていません私が得ているエラーです。私がここでやろうとしているのは、リンクをクリックすると、updatedproductの列を更新することです。ここで

スクリーンショット

enter image description here

ですUPDATE:

私はこのエラーを取得する:

Conversion failed when converting the nvarchar value '__Page' to data type int.

enter image description here

+5

5つの質問で[email protected]を交換してください。 SQLチュートリアルを受けてください。これはチュートリアルのサイトではありません。そして、あなたはMicrosoft SQL Server上で、昨晩後に私たちが今知っているmysqlではありません。 – Drew

答えて

3

ProductIDは両方TABLに存在しているので、この場合、WHERE句はあいまいであると判断します。だから、

は本当の基本的なSQLの概念それらのすべては、8時間で[email protected]

update o set o.Updatedproduct = p.ProductQuantity - o.Totalproduct 
from CustomerProducts o 
inner join Products p 
on o.ProductID = p.ProductID WHERE [email protected] 
+0

@ReineVirayあなたの質問のコードに '__Page'がありません。 – user3185569

+0

@ReineVirayデータベースの更新にトリガーがありますか? – user3185569

+0

トリガーサーは何を意味しますか?実際には、私は今、私は今ボタンを試してみるとうまくいきますが、問題はそれが 'updatedproduct column'をすべて更新していて、リンクをクリックした後に一つの列を更新するだけです。ありがとうございます –

関連する問題