如何减少到数据库的次数 [英] how to reduce number of trips to database

查看:60
本文介绍了如何减少到数据库的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的产品数据库表中的每个项目都有自己的总帐(GL)销售帐户代码和相应的说明以及库存帐户和库存描述。现在只有帐户代码存储在产品表中 - 这意味着当我从产品表中获得
GL销售帐户时,我必须在会计科目表中运行查询以获得适当的描述。然后另外库存帐户代码意味着我必须从
相同的表中对库存帐户描述进行另一个查询。这些只是两个领域。产品还有一个商品销售成本帐户和库存调整帐户,这意味着我必须多次往返数据库以检索这些代码的描述。我的问题是如何减少
到数据库的往返次数?

Each Item in our products database table has its own General Ledger (GL) sales account code and corresponding description and Inventory Account and Inventory desription. Now only the account code are stored in the products table - which means when I have the GL Sales Account from the products table I have to run a query in the charts of accounts table to get proper description for it. and then in addition Inventory account code meaning I have to do another query for the Inventory account description from the same table. these are just two fields only. products also have a Cost of Goods Sold Account and Inventory Adjustment Account meaning I have to do so many round trips to the database to retrieve the description of these codes. My question is How can I reduce the Number of round trips to the database?

TxtSaleGLCode.Text= Convert.ToString(row["GLSalesAccount"]);
                TxtSalesGLDescription.Text = ProceduresClass.GetGLDescriptionFromChartMaster(Convert.ToString(row["GLSalesAccount"]));
                TxtInventoryAccountGLCode.Text=Convert.ToString(row["GLInventoryAccount"]);
                TxtInventoryAccountGLDescription.Text = ProceduresClass.GetGLDescriptionFromChartMaster(Convert.ToString(row["GLInventoryAccount"]));

如果您认为可以实现它

推荐答案

建立一个单个SQL查询,视图或sproc调用,它们在数据库端将表连接在一起。然后将结果作为单个结果集返回。这需要单个数据库调用。如果您不知道如何连接表,那么您可以在SQL论坛中发布表结构
,它们可以帮助您找出最佳方法。一个好的DBA可以做同样的事情。

Build a single SQL query, view or sproc call that joins the tables together on the database side. Then return the results as a single resultset. This requires a single database call. If you don't know how to join tables then you can post your table structure in the SQL forums and they can help you figure out the optimal approach. A good DBA can do the same thing.

在你的C#方面,它取决于你用于实际代码的数据访问库,但它们都支持查询,视图和sproc调用。使用数据读取器从数据库中读取数据并将其放入您的UI将用作其数据绑定层的一部分的自定义业务对象中。

On your C# side it depends on what data access library you're using for the actual code but all of them support queries, views and sproc calls. Use a data reader to read the data back from the database and place it into your custom business objects that your UI will use as part of its data binding layer.


这篇关于如何减少到数据库的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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