如何从BLL返回多表连接值

发布于 2024-09-11 21:09:47 字数 1659 浏览 6 评论 0原文

这个问题是关于我正在为我的最终学校项目使用 DAL-BLL 架构创建的 ASP.NET Web 服务。

我有一个存储过程,它是一个带有 2 个表的内部联接的选择查询。因此,存储过程返回多表值。我的 DAL tableAdapter 方法之一访问此存储过程。如何检索 BLL 中的返回值?我是否必须创建一个类似于存储过程返回的类结构?或者有没有直接的方法可以达到同样的目的?非常感谢帮助。如果有人需要代码小程序来更好地理解,请告诉我。谢谢

这里有一些更多信息: 我在 DAL 中使用 SQL 数据集 (.xsd)。所以我有一个名为“保险”的数据表,其中有一个表适配器。适配器中的查询之一引用了具有内部联接的存储过程。所以我的 SP 看起来像:

ALTER PROCEDURE dbo.GetInsurancesPaged
    (
        @startRowIndex int,
        @maximumRows int,
        @patientID int
    )
AS
    select * from
    (
    SELECT Insurance.insuranceID, Insurance.memberID, Insurance.groupID, Insurance.accountType, Insurance.comments, Insurance.patient, Insurance.company, InsuranceCompany.companyID, InsuranceCompany.companyName, InsuranceCompany.address, InsuranceCompany.phone, InsuranceCompany.fax, ROW_NUMBER() over (order by Insurance.dateModified DESC) as ROWRANK
FROM Insurance INNER JOIN InsuranceCompany ON Insurance.company = InsuranceCompany.companyID
WHERE Insurance.patient = @patientID
    )
    AS DataWithRowNumbers
WHERE ROWRANK > @startRowIndex AND ROWRANK <= (@startRowIndex + @maximumRows)

所以这个 SP 返回一个数据表,它将是内连接中 2 个表的组合。如果我错了,请纠正我。

现在在我的 BLL 中,我有:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public mySys.InsuranceDataTable GetInsurancesPaged(int startRowIndex, int maximumRows, int patientID)
    {
       return insAdapter.GetInsurancesPaged(startRowIndex, maximumRows, patientID);
    }

其中 insAdapter 是 InsuranceTableAdapter 的一个实例

这会在执行时出现错误。我可以成功执行 SP,所以我认为问题只是 bcz 我试图从 BLL 返回错误的数据表。 请帮我解决这个问题。

This question is regarding the ASP.NET webservice that i am creating using the DAL-BLL architecture for my final school project.

I have a stored procedure, which is a select query with an inner join for 2 tables. Hence the stored procedure returns multi-table value. One of my DAL tableAdapter methods accesses this stored procedure. How do i retrieve the return value in the BLL? Do i have to create a class structure similar to the one supposed to be returned by the stored proc? or is there a direct way to achieve the same? Help greatly appreciated. Please let me know if someone needs code applet to get a better understanding. Thanks

Here is some more information:
I am using the SQL dataset (.xsd) in DAL. So i have a datatable called "Insurance", which has a tableAdapter. One of the queries in the adapter references to a stored procedure, which has an inner join. So my SP looks like:

ALTER PROCEDURE dbo.GetInsurancesPaged
    (
        @startRowIndex int,
        @maximumRows int,
        @patientID int
    )
AS
    select * from
    (
    SELECT Insurance.insuranceID, Insurance.memberID, Insurance.groupID, Insurance.accountType, Insurance.comments, Insurance.patient, Insurance.company, InsuranceCompany.companyID, InsuranceCompany.companyName, InsuranceCompany.address, InsuranceCompany.phone, InsuranceCompany.fax, ROW_NUMBER() over (order by Insurance.dateModified DESC) as ROWRANK
FROM Insurance INNER JOIN InsuranceCompany ON Insurance.company = InsuranceCompany.companyID
WHERE Insurance.patient = @patientID
    )
    AS DataWithRowNumbers
WHERE ROWRANK > @startRowIndex AND ROWRANK <= (@startRowIndex + @maximumRows)

So this SP returns a datatable which will be a combination of the 2 tables in the inner join. Please correct me if i am wrong.

Now in my BLL, i have:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public mySys.InsuranceDataTable GetInsurancesPaged(int startRowIndex, int maximumRows, int patientID)
    {
       return insAdapter.GetInsurancesPaged(startRowIndex, maximumRows, patientID);
    }

where insAdapter is an instance of insuranceTableAdapter

This gives an error on execution. I can execute the SP successfully, so i think the problem is only bcz i am trying to return a wrong datatable from the BLL.
Please help me solve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘羡 2024-09-18 21:09:47

如果使用 ADO .Net 数据集。向导将明确地为其创建一个表。现在从数据访问层执行以下步骤

1. Create a object of dataset. (DLL)

Private YourCustomeDataSetDatatable  DataAccess()
{
 YourCustomDataSet ds = new YourCustomDataSet();  // also called strongly typed dataset
YourCustomeDataSetDatatable dt = ds.YourCustomeDataSetDatatable ()
YourCustomeDataSetTableAdapter ta = new ds.YourCustomeDataSetTableAdapter (); // table adapter that will be invoked 
ta.Fill(dt); // or if you have set to return only you can also use GetData()
}

2. Now in business layer

Private YourCustomeDataSetDatatable  DataAccess()
{
// create a object of DLL. 
MyDAL myDal = new MyDAL ();
return myDal.DataAccess();
}
  1. 通过遵循 BLL 的创建对象并调用该方法,在 UI 页面上捕获此内容。在 BLL 中,您还可以执行各种操作来降低 ui 中的代码并使其免受各种操作的影响。

If using ADO .Net dataset. The wizard will definetly create a table for the same. now from the dataaccess layer, do the following steps

1. Create a object of dataset. (DLL)

Private YourCustomeDataSetDatatable  DataAccess()
{
 YourCustomDataSet ds = new YourCustomDataSet();  // also called strongly typed dataset
YourCustomeDataSetDatatable dt = ds.YourCustomeDataSetDatatable ()
YourCustomeDataSetTableAdapter ta = new ds.YourCustomeDataSetTableAdapter (); // table adapter that will be invoked 
ta.Fill(dt); // or if you have set to return only you can also use GetData()
}

2. Now in business layer

Private YourCustomeDataSetDatatable  DataAccess()
{
// create a object of DLL. 
MyDAL myDal = new MyDAL ();
return myDal.DataAccess();
}
  1. Catch this on your UI page by following the creating object of BLL and call the method. Here in BLL you can also do various operations to lowered the codes in you ui and keeping it clean from various manipulations.
冰火雁神 2024-09-18 21:09:47

找到了解决方案:)
终于成功了。

我使用数据集设计器创建了一个新的表适配器,并将 SP 称为其中的查询之一。由此创建的数据表包含所有字段(来自 Insurance 和 InsuranceCompany)。现在,ASP.NET 可以检测到返回类型是新创建的数据表。
就像魅力一样。

如果有更好的方法来解决这个问题,欢迎评论。

感谢大家抽出宝贵的时间。

Found a solution :)
Finally got it working.

I created a new table adapter using the Dataset designer, and called the SP as one of the queries there. The datatable thus created, has all the fields (from Insurance and InsuranceCompany) included. Now, ASP.NET can detect that the return type is the newly created datatable.
Works like a charm.

If there is a better way to solve this, please comment.

Thank you all for your time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文