如何在C#.net中使用网格作为计费表单?

问题描述:

嘿,人们,是C#.net中的一个新的夜间错误,我正在尝试为商店,餐厅等(用于学习)制作一个帐单,我可以成功地将网格与SQL DB连接起来.
由于网格中有不同的条目(序列号,详细信息,数量和价格)以及显示总金额的位置(文本框),因此,通过Button click事件(Total Button)位于网格之外,所以有人可以建议我吗单击总计"按钮后,如何将详细信息的总价带到网格外部的文本框中.

Hey People ,m new nocturnal bug in C#.net and i was trying to make a billing form for shops,retaurents etc etc(for learning),I could successfuly connect grid with the SQL DB.
Since there are different entries in the Grid ( S.N,Particulars,Quantity and price) and the place where the Total amount is shown (Text boX),with the Button click event(Total Button) is outside the Grid so,Can anybody suggest me how to bring the total Price of the particulars into the textbox which is outside the grid, after clicking the Total Button.

编写可计算出总计并放入的代码它进入文本框.理想情况下,您应该将值存储在数据库中并从中获取总计,但是您可以根据需要通过访问网格中的值来做到这一点.
Write code that works out hte total and puts it in to the textbox. You should ideally store your values in the DB and get your total from there, but you can do it by accessing values in your grid if you want.


您可以直接从数据库中获取总和.数据库使用sql查询:

You can get the sum directly from the database using sql query:

SELECT SUM(field_name) FROM table_name



或者您也可以在代码隐藏文件中执行以下操作:



or you can do it in code-behind file as:

double amount = 0;
        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {
            amount += Convert.ToDouble(dataGridView1.Rows[i].Cells[cell_index].Value);
        }