货币兑换数据透视表

时间:2015-11-24 14:20:36

标签: c# .net sql-server datagridview pivot-table

我在数据库中有一个带有此存储过程的数据转换货币兑换表。

USE XXX
GO
/****** Object:  StoredProcedure [dbo].[usp_ExRatesPerDate]    Script Date: 24.11.2015 13:53:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_ExRatesPerDate] 
    @Month int,
    @Year int
AS 
    SET NOCOUNT ON;

    SELECT *
FROM (
    SELECT a.Currency_CODE as '\',b.ToCurrency as CUR,ISNULL(b.Rate,0) as RATES
FROM db_datawriter.ExRatesPerMonth b
INNER JOIN dbo.Currencies a ON a.Currency_CODE=b.FromCurrency
INNER JOIN db_datawriter.ExRatesFixings c ON b.ExRatesFixings_ID=c.ID
WHERE c.Year=@Year AND c.Month=@Month
)as s
PIVOT
(
    MAX(RATES) FOR CUR IN 
    (CHF,CNY,CZK,EUR,GBP,HKD,INR,IRR,USD)

)ID

现在我想在用户更改datagridview

中的某些值时更新数据库

Datagrid View Exchange Rates Date And Rate Tables

如何正确更新数据库表?

 - ID   Rate    FromCurrency    ToCurrency  ExRatesFixings_ID
7   3.00    USD CHF 2
8   2.00    IRR CHF 2
9   0.00    INR CHF 2
10  0.00    HKD CHF 2
11  0.00    GBP CHF 2
12  0.00    EUR CHF 2
13  0.00    CZK CHF 2
14  0.00    CNY CHF 2
15  0.00    CHF CHF 2
16  0.00    USD CNY 2
17  4.00    IRR CNY 2
18  0.00    INR CNY 2
19  0.00    HKD CNY 2
20  0.00    GBP CNY 2
21  0.00    EUR CNY 2
22  0.00    CZK CNY 2
23  0.00    CNY CNY 2
24  0.00    CHF CNY 2
25  0.00    USD CZK 2
26  0.00    IRR CZK 2
27  0.00    INR CZK 2
28  0.00    HKD CZK 2
29  0.00    GBP CZK 2
30  0.00    EUR CZK 2
31  0.00    CZK CZK 2
32  0.00    CNY CZK 2
33  0.00    CHF CZK 2
34  0.00    USD EUR 2
35  0.00    IRR EUR 2
36  0.00    INR EUR 2
37  0.00    HKD EUR 2
38  0.00    GBP EUR 2
39  0.00    EUR EUR 2
40  0.00    CZK EUR 2
41  0.00    CNY EUR 2
42  0.00    CHF EUR 2
43  0.00    USD GBP 2
44  0.00    IRR GBP 2
45  0.00    INR GBP 2
46  0.00    HKD GBP 2
47  0.00    GBP GBP 2
48  0.00    EUR GBP 2
49  0.00    CZK GBP 2
50  0.00    CNY GBP 2
51  0.00    CHF GBP 2
52  0.00    USD HKD 2
53  0.00    IRR HKD 2
54  0.00    INR HKD 2
55  0.00    HKD HKD 2
56  0.00    GBP HKD 2
57  0.00    EUR HKD 2
58  0.00    CZK HKD 2
59  0.00    CNY HKD 2
60  0.00    CHF HKD 2
61  0.00    USD INR 2
62  0.00    IRR INR 2
63  0.00    INR INR 2
64  0.00    HKD INR 2
65  0.00    GBP INR 2
66  0.00    EUR INR 2
67  0.00    CZK INR 2
68  0.00    CNY INR 2
69  0.00    CHF INR 2
70  0.00    USD IRR 2
71  0.00    IRR IRR 2
72  0.00    INR IRR 2
73  0.00    HKD IRR 2
74  0.00    GBP IRR 2
75  0.00    EUR IRR 2
76  0.00    CZK IRR 2
77  0.00    CNY IRR 2
78  0.00    CHF IRR 2
79  0.00    USD USD 2
80  0.00    IRR USD 2
81  0.00    INR USD 2
82  0.00    HKD USD 2
83  0.00    GBP USD 2
84  0.00    EUR USD 2
85  0.00    CZK USD 2
86  0.00    CNY USD 2
87  0.00    CHF USD 2

这是执行数据透视程序的C#代码:

// initialize Member for ExRates
MasterData.dtExRates = new DataTable("ExRates");
MasterData.sqlExRates = new SqlCommand("dbo.usp_ExRatesPerDate", MasterData.sqlConn);
MasterData.sqlExRates.Parameters.Add(new SqlParameter("@Month", SqlDbType.Int));
MasterData.sqlExRates.Parameters.Add(new SqlParameter("@Year", SqlDbType.Int));
MasterData.sqlExRates.CommandType = CommandType.StoredProcedure;
MasterData.daExRates = new SqlDataAdapter(sqlExRates);
MasterData.daExRates.InsertCommand = new SqlCommand("dbo.usp_ExRatesPerDate", MasterData.sqlConn);
MasterData.bsExRates = new BindingSource();

0 个答案:

没有答案