单击按钮的总价

时间:2018-08-02 14:58:31

标签: c# html sql asp.net stored-procedures

当我单击行按钮public static int myInt = 0;时,我试图将行的价格添加到全局变量ADD中,然后根据所单击的按钮显示总价格。这是我的尝试,但是似乎没有用。

HTML代码:

       <asp:GridView ID="GridView2" runat="server" Width="425px">

              <Columns>
                <asp:ButtonField ButtonType="Button" CommandName="info" Text="ADD" />
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F7F7F7" />
            <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
            <SortedDescendingCellStyle BackColor="#E5E5E5" />
            <SortedDescendingHeaderStyle BackColor="#242121" />

        </asp:GridView>
 <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

这是我的C#方法:

protected void servicesCheckout(Object sender, GridViewCommandEventArgs e) {
    int row = Convert.ToInt32(e.CommandArgument.ToString());
    Session["n"] = GridView2.Rows[row].Cells[1].Text;

    string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
    SqlConnection conn = new SqlConnection(connStr);
    SqlCommand cmd = new SqlCommand("calcSum", conn);
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.Add(new SqlParameter("@ServiceID", Session["n"].ToString()));//HERE
    SqlParameter flag = cmd.Parameters.Add("@sum", SqlDbType.Int);
    flag.Direction = ParameterDirection.Output;

    conn.Open();
    cmd.ExecuteNonQuery();

    myInt = Convert.ToInt32(cmd.Parameters["@sum"].Value);
    TextBox1.Text = "The total sum of the prices is: "+myInt;

    conn.Close();
}

最后,这是我的calcSum SQL proc,它输出每个服务的价格值:

create   proc calcSum
@ServiceID int,
@sum int out
as 
begin 
set @sum= (select price from Extra_Services_by_Employee ee where ee.ServiceID=@ServiceID )
end

0 个答案:

没有答案