从Access数据库添加总计 [英] Add total from Access Database
问题描述
我正在制造一个计算器,该计算器将从列表框中获取一本书的书名,在链接的数据库中查找该书,然后计算该书的价格.然后,价格将计算为列表框中所有书籍的小计,然后加上税款和最终价格 全部显示在标签中.只需按一下按钮即可开始.我被困住了,这是我开始的地方,但是没有用.
I am making a calculator that will take a title of a book from a list box, find the book in a linked database and take the price of that book. The price would then be calculated as a subtotal of all the books in the list box and then add tax and a final total show in labels. It would all be started with the press of a button. I am stuck, this was where I started but it is not working.
点心作为Double
For x As Integer = 0到Cart_List.Items.Count-1
sum + = Val(Cart_List.Items.Item(x).ToString)
Next
Dim sum As Double
For x As Integer = 0 To Cart_List.Items.Count - 1
sum += Val(Cart_List.Items.Item(x).ToString)
Next
推荐答案
这是一个非常简单的问题,因此我认为这是家庭作业.
It is a very simple question therefore I think it is homework.
您要做的是使用TableAdapter创建数据表
What you have to do is create a datatable with a TableAdapter
然后您得到一张桌子.您将表"设置为列表框的数据源
Then you get with that a table. That you set to the Table as datasource of the listbox
LB.DataSource =数据表
LB.DataSource = theDataTable
您设置为Displaymember的名称
LB.DisplayMember =名称"
The Name you set to the Displaymember
LB.DisplayMember = "Name"
,并以相同的方式向价值成员收取价格.
and in the same way the price to the valuemember.
处理索引更改事件的方法中现在唯一需要的代码是
The only code you need now in the method which handles the index changed event is
Sum += Cdec(LB.Value)
然后将sum设置为标签
and then set sum to the label
SubTot_lbl = Sum.ToString("9,99")(英语9.99)
SubTot_lbl = Sum.ToString("9,99") (in English 9.99)
这篇关于从Access数据库添加总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!