将访问应用程序移动到C#前端和SQl后端

时间:2014-11-17 21:54:50

标签: c# sql-server stored-procedures ms-access-2010 sql-view

最近我的经理给了我一个新任务,就是将我们的一个处理净重计算的访问应用程序移动到C#并告诉我使用sql作为后端。

所以首先我通过转到数据库工具下的移动数据部分,几次点击并将所有数据自动迁移到sql,将所有数据库从访问权限移到了sql。 第二次我试图在c sharp 第三中模拟获取表单上的访问表单我看到几个按钮基本上是直接从表中读取数据所以我创建了一个带有数据的模态表单网格并从我的主窗体调用模态窗体,并加载了数据库中的数据。

现在关于其余按钮的问题

我在访问应用程序中有很多查询,并且每个查询都被另一个查询引用,似乎查询就像访问中的表一样,我不知道如何在SQL Server中完成此操作,如果我让查询工作我可以创建一个没有任何问题的报告。

我尝试创建一个视图但没有帮助,因为它无法找到引用的表,存储过程看起来像是要走的路,但我对存储过程没有太多的了解。

来自访问者的查询

生成的报告称为“组合主数据报告”

SELECT [Net Weight Master Data Query].[Unit UPC Base Item], [Net Weight Master Data Query].[Item Description], [Net Weight Master Data Query].[Production Line], [Production Lines].[Production Line Description], [Net Weight Master Data Query].[Preset Number], [Net Weight Master Data Query].[Weight Factor], [Net Weight Master Data Query].Piece, [Net Weight Master Data Query].[Pcs Per Unit], [Net Weight Master Data Query].[Upper Limit Unit], [Net Weight Master Data Query].[Upper Limit Factor], [Net Weight Master Data Query].[Piece Wt (g)], [Net Weight Master Data Query].[Upper Limit (g)], [Net Weight Master Data Query].[Lower Limit (g)], [Net Weight Master Data Query].[Label Wt (g)], [Net Weight Master Data Query].[Tare Wt (g)], [Net Weight Master Data Query].[Constant Tare Wt (g)], [Net Weight Master Data Query].[Tare Variation Factor (g)], [Net Weight Master Data Query].[Target Wt (g)], [Net Weight Master Data Query].[Reject Wt (g)], [Net Weight Master Data Query].[Repair Min Wt (g)], [Net Weight Master Data Query].[MAV (g)], [Net Weight Master Data Query].[MAW (g)], [Net Weight Master Data Query].[Pkg Length (mm)], [Net Weight Master Data Query].[Film Product Code], [Net Weight Master Data Query].[Film Width (mm)], [Net Weight Master Data Query].[Forming Tube (mm)], [Net Weight Master Data Query].[Type of Jaws], [Overpack Percentages].[Std RM $/LB], [Overpack Percentages].[Avg Overpack Percentage], [Net Weight Master Data Query].[Last Updated]
FROM ([Net Weight Master Data Query] LEFT JOIN [Production Lines] ON [Net Weight Master Data Query].[Production Line] = [Production Lines].[Production Line]) LEFT JOIN [Overpack Percentages] ON [Net Weight Master Data Query].[Unit UPC Base Item] = [Overpack Percentages].[Unit UPC Base Item]
ORDER BY [Net Weight Master Data Query].[Unit UPC Base Item], [Net Weight Master Data Query].[Production Line];

如您所见,引用的第一列是[净重主数据查询]

以下是净重主数据查询

SELECT [Net Weight Master Data].[Unit UPC Base Item], [Item Descriptions].[Item Description], [Net Weight Master Data].[Production Line], [Production Lines].[Production Line Description], [Net Weight Master Data].[Preset Number], [Net Weight Master Data].[Package Type], [Net Weight Master Data].[Weight Factor], [Net Weight Master Data].Piece, [Net Weight Master Data].[Pcs Per Unit], [Net Weight Master Data].[Upper Limit Unit], [Net Weight Master Data].[Upper Limit Factor], IIf([upper limit unit]="g","",(CInt(([label wt (g)]/[Pcs per unit])*10))/10) AS [Piece Wt (g)], ([mav (g)]-[scale deviation factor]-[tare variation factor (g)])/[weight factor] AS UL1, [UL1]-Fix([UL1]) AS UL2, IIf([Package Type] Is Not Null,[UL1],IIf([UL2]=0,Fix([UL1]),IIf([UL2]>0 And [UL2]<0.51,Fix([UL1])+[Rounding Factor1],Fix([UL1])+[rounding factor2]))) AS UL3, IIf([Package Type]="Bar",10,IIf([upper limit unit]="g",([UL3]*[weight factor]),[piece wt (g)]*[Upper Limit Factor])) AS [Upper Limit (g)], IIf([upper limit unit]="g",([UL3]*[weight factor]),0) AS [Lower Limit (g)], [Net Weight Master Data].[Label Wt (g)], [Net Weight Master Data].[Tare Wt (g)], [Net Weight Master Data].[Constant Tare Wt (g)], [Net Weight Master Data].[Tare Variation Factor (g)], [Label Wt (g)]+[tare wt (g)] AS [Target Wt (g)], [label wt (g)]-[lower limit (g)] AS [Reject Wt (g)], IIf([package type]="Bar",([Label Wt (g)]-[mav (g)]+[tare wt (g)]),IIf([package type]="10 Pack",([Label Wt (g)]-[mav (g)]+[tare wt (g)])+2.5,([Label WT (g)]-[mav (g)]+[tare wt (g)])+5)) AS [Repair Min Wt (g)], [Maximum Allowable Variations].[MAV (g)], [Production Lines].[Scale Deviation Factor], [label wt (g)]-[mav (g)] AS [MAW (g)], [Net Weight Master Data].[Pkg Length (mm)], [Net Weight Master Data].[Film Product Code], [Net Weight Master Data].[Film Width (mm)], [Net Weight Master Data].[Forming Tube (mm)], [Net Weight Master Data].[Type of Jaws], [Net Weight Master Data].[Last Updated], [Production Lines].[Rounding Factor1], [Production Lines].[Rounding Factor2]
FROM (([Net Weight Master Data] LEFT JOIN [Production Lines] ON [Net Weight Master Data].[Production Line] = [Production Lines].[Production Line]) INNER JOIN [Maximum Allowable Variations] ON [Net Weight Master Data].[Label Wt (g)] = [Maximum Allowable Variations].[Labeled Quantity (g)]) LEFT JOIN [Item Descriptions] ON [Net Weight Master Data].[Unit UPC Base Item] = [Item Descriptions].[Unit UPC Base Item]
ORDER BY [Net Weight Master Data].[Unit UPC Base Item], [Net Weight Master Data].[Production Line];

在上面的查询[项目描述]被引用,这是另一个查询

[项目描述]查询

SELECT ItemDescLookups.[Unit UPC Base Item], First(ItemDescLookups.[Item Description]) AS [Item Description]
FROM ItemDescLookups
GROUP BY ItemDescLookups.[Unit UPC Base Item];

所以我们需要创建一个巨大的存储过程,它看起来像在查询中引用查询所谓的子查询,但是有很多IFF和其他语句如FIRST我们如何将这些转换为SQL。如果有人可以帮我创建一个存储过程我真的很感激它,因为所有其他按钮创建不同的报告,如果我知道如何做一个我可以轻松地为其他人做同样的事情并将我的应用程序迁移到csharp。

1 个答案:

答案 0 :(得分:1)

A&#34;查询&#34;在Access中对应于&#34; View&#34;在SQL Server中。就像在Access中一样,SQL Server View通常可以像其他视图中的表一样使用,所以在SQL Server中你可以拥有

CREATE VIEW ViewX AS
SELECT ... FROM Table1 WHERE ...

然后您可以在另一个视图中使用该视图,例如

CREATE VIEW ViewY AS
SELECT ... FROM ViewX WHERE ...

因此,您可能根本不需要使用存储过程,如果您所做的只是在Access中重新创建已保存查询的行为。

至于Access SQL和T-SQL(SQL Server使用的方言)之间的差异,有几种,在Stack Overflow上已经讨论了很多次。您需要做的是尝试将SQL语句从Access SQL转换为T-SQL,如果您遇到特定问题,那么

  1. 查看How to Ask,然后
  2. ask a new specific question