[英]Moving Access Application to C# front end and SQl Backend
recently my manager gave me a new task, it was to move one of our access application that handles the net weight calculation to C# and told me to use sql as a back end. 最近,我的经理给了我一项新任务,那就是将处理净重计算的Access应用程序之一移至C#,并告诉我使用sql作为后端。
so first i moved all the database from access to sql by going to the move data section under database tools and few clicks and all the data was automatically migrated to sql. 因此, 首先,我进入数据库工具下的“移动数据”部分,只需单击几下,即可将所有数据库从对sql的访问中移出,所有数据均自动迁移到sql。 second i tried to mimic the access forms onto win forms in c sharp third i saw that few buttons were basically reading data directly from the table so i created a modal form with data grid and called the modal form from my main form and the data from the database got loaded. 第二,我试图将访问表单模仿为c中的获胜表单。 第三,我看到几乎没有按钮基本上直接从表中读取数据,所以我创建了带有数据网格的模态表单,并从我的主表单和从数据库已加载。
NOW THE QUESTION ON THE REST OF THE BUTTONS 现在对其余按钮的问题
I have many many queries in the access application and each query is getting referenced by another query, it seems as though the queries are like tables in access, i am not sure how to go about accomplishing this in SQL Server, if i get the query to work i can create a report with out any problem. 我在Access应用程序中有很多查询,每个查询都被另一个查询引用,似乎这些查询就像是Access中的表,如果我得到查询,我不确定如何在SQL Server中完成此操作工作,我可以创建一个没有任何问题的报告。
I tried creating a view and that was not helping because it can't find the referenced table, stored procedure seems like the way to go but i dont have much knowledge on stored procedures. 我尝试创建一个视图,但没有帮助,因为它找不到引用的表,存储过程似乎是一种解决方法,但是我对存储过程了解不多。
Queries From Acesss 存取查询
The report being generated is called Combined Master Data Report 生成的报告称为合并主数据报告
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];
As you can see above the first columns getting referenced is [Net Weight Master Data Query] 如您在上方看到的,被引用的第一列是[净重主数据查询]
Here is Net Weight Master Data Query 这是净重主数据查询
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];
In the above query [Item Descriptions] gets referenced which is another query 在上面的查询中,引用了[项目描述],这是另一个查询
[Item Descriptions] query below [项目说明]查询如下
SELECT ItemDescLookups.[Unit UPC Base Item], First(ItemDescLookups.[Item Description]) AS [Item Description]
FROM ItemDescLookups
GROUP BY ItemDescLookups.[Unit UPC Base Item];
So we need to create a giant stored procedure it looks like that references there queries within queries so called sub-queries but there are lot of IFF and other statements like FIRST how do we convert these to SQL. 因此,我们需要创建一个巨大的存储过程,看起来像在查询中引用了那里的查询,即所谓的子查询,但是有很多IFF和其他语句(例如FIRST),我们如何将它们转换为SQL。 IF anyone can help me create a Stored Procedure i would really appreciated it because all the other buttons create different reports, if i know how to do one i can easily do the same for the others and migrate my application over to csharp. 如果有人可以帮助我创建存储过程,我将不胜感激,因为所有其他按钮都创建了不同的报告,如果我知道该怎么做,那么我可以轻松地对其他按钮执行同样的操作,并将我的应用程序迁移到csharp。
A "Query" in Access corresponds to a "View" in SQL Server. Access中的“查询”对应于SQL Server中的“视图”。 Just like in Access, a SQL Server View can often be used like a Table in other Views, so in SQL Server you could have 就像在Access中一样,SQL Server视图通常可以像其他视图中的表一样使用,因此在SQL Server中,
CREATE VIEW ViewX AS
SELECT ... FROM Table1 WHERE ...
and then you could use that View in another View, eg, 然后您可以在其他视图中使用该视图,例如,
CREATE VIEW ViewY AS
SELECT ... FROM ViewX WHERE ...
So you may not need to use a Stored Procedure at all, if all you are doing is recreating the behaviour of saved Queries in Access. 因此,如果您要做的只是重新创建Access中已保存查询的行为,则可能根本不需要使用存储过程。
As for the differences between Access SQL and T-SQL (the dialect used by SQL Server), there are several, and they have been discussed many, many times here on Stack Overflow. 至于Access SQL和T-SQL(SQL Server使用的方言)之间的区别,有几个,并且在Stack Overflow上已对此进行了很多次讨论。 What you need to do is try converting the SQL statements from Access SQL to T-SQL and if you get stuck on a particular issue then 您需要做的是尝试将SQL语句从Access SQL转换为T-SQL,如果遇到特定问题,那么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.