如何计算2表量和显示到DataGridView [英] How to Calculate 2 Table Amount and Display to DataGridView

查看:92
本文介绍了如何计算2表量和显示到DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好







我正在使用2张桌子(1张桌子是Fees_Transaction另一张桌子是FeesMaster)。我想加入2 Talbe并匹配类和Regno从数量上计算并显示在DataGridView中。



我尝试使用此代码但它是' notWorking ...请帮助我..如何加入和校准特定的regno +班级金额。





费用_交易表数据
Regno ST_Name Class Section Amount_Paid FeeType

A600 BBBB IA 500 Team-1

A900 PPPP IA 750 Team-1

A700 DSDSDSDSD IA 500团队-1

A700 DSDSDSDSD IA 250团队-1

A700 DSDSDSDSD IA 350 Jan >
A600 BBBB IA 150 Team-1

A900 PPPP IA 200 Jan







FeesMaster:表数据< br $>
Reg no Class Section Sname FeeType FeeAmount

A600 IA BBBB Team-1 650

A700 IA DSDSDSDSD Team-1 750

A900 IA PPPP团队-1 750

A600 IA BBBB 1月650

A900 IA PPPP 1月650



我想在DATAGRIDVIEW中这样说

Reg no ST_Name Amount_Paid FeeAmount FeeType Class Section



A600 BBBB 650 1300总计我A

A700 DSDSDSDSD 1400 1400总计我是一个

A900 PPPP 950 1400总计我是一个





Dim strSQL5 As String =SELECT Fees_Transaction.Regno,Fees_Transaction.ST_Name ,SUM(Fees_Transaction.Amount_Paid)为FTAmountPaid,FeeAmount FROM Fees_Transaction INNER JOIN(SELECT类,SUM(FeeAmount)FROM FeesMaster WHERE FeesMaster.Class =''&cboClass.Text&'')作为FeeAmount WHERE Fees_Transaction.Class =' '&cboClass.Text&''GROUP BY Fees_Transaction.Regno,Fees_Transaction.ST_Name

Hi All



I am Using 2 Tables (1 Table is Fees_Transaction another one Table is FeesMaster). I Want to JOIN 2 Talbe and Matching the Class and Regno From that Amount Shoud be Calculate and Display in the DataGridView.

I Try to This Code but it''s notWorking... Please Help me.. How to Join and Caluclate Particular regno+Class amount.


Fees_Transaction Table Data
Regno ST_Name Class Section Amount_Paid FeeType
A600 BBBB I A 500 Team-1
A900 PPPP I A 750 Team-1
A700 DSDSDSDSD I A 500 Team-1
A700 DSDSDSDSD I A 250 Team-1
A700 DSDSDSDSD I A 300 Jan
A700 DSDSDSDSD I A 350 Jan
A600 BBBB I A 150 Team-1
A900 PPPP I A 200 Jan



FeesMaster : Table Data
Reg no Class Section Sname FeeType FeeAmount
A600 I A BBBB Team-1 650
A700 I A DSDSDSDSD Team-1 750
A900 I A PPPP Team-1 750
A600 I A BBBB Jan 650
A700 I A DSDSDSDSD Jan 650
A900 I A PPPP Jan 650

I WANT LIKE THIS IN DATAGRIDVIEW
Reg no ST_Name Amount_Paid FeeAmount FeeType Class Section

A600 BBBB 650 1300 TOTAL I A
A700 DSDSDSDSD 1400 1400 TOTAL I A
A900 PPPP 950 1400 TOTAL I A



Dim strSQL5 As String = "SELECT Fees_Transaction.Regno, Fees_Transaction.ST_Name, SUM(Fees_Transaction.Amount_Paid) as FTAmountPaid, FeeAmount FROM Fees_Transaction INNER JOIN (SELECT Class, SUM(FeeAmount) FROM FeesMaster WHERE FeesMaster.Class=''" & cboClass.Text & "'') as FeeAmount WHERE Fees_Transaction.Class=''" & cboClass.Text & "'' GROUP BY Fees_Transaction.Regno,Fees_Transaction.ST_Name"

推荐答案

我不确定我的问题是否正确,我想你应该这样做的方式如下



Tbl_1

a

b

c



Tbl_2

d

e

f



如果你想要列a和d中常见的数据(在你的案例类和regno中),那么你可以执行以下操作

SELECT tbl_1.a,tbl_1.b ,tbl_1.c

FROM tbl_1 INNER JOIN tbl_2 on tbl_1.a = tbl_2.d

GROUP BY tbl_1.a,tbl_1.b,tbl_1.c



修改上述内容以满足您的要求
I''m not sure if I got your question right, I guess the way you should do it as below

Tbl_1
a
b
c

Tbl_2
d
e
f

and if you want data that is common in column a and d (in your case class and regno) then you do the below
SELECT tbl_1.a,tbl_1.b,tbl_1.c
FROM tbl_1 INNER JOIN tbl_2 on tbl_1.a = tbl_2.d
GROUP BY tbl_1.a, tbl_1.b, tbl_1.c

modify the above to suit your requirement


这篇关于如何计算2表量和显示到DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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