如何在C#.net中使用网格作为计费表单? [英] How To Use Grid As Billing Form in C#.net?

查看:59
本文介绍了如何在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);
        }


这篇关于如何在C#.net中使用网格作为计费表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆