Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以接受SQL查询结果的C#Web App条件语句_C#_Arrays_Conditional - Fatal编程技术网

可以接受SQL查询结果的C#Web App条件语句

可以接受SQL查询结果的C#Web App条件语句,c#,arrays,conditional,C#,Arrays,Conditional,我正在开发一个较旧的CMS(C#,Visual Studio 2005,.NET 2.0),该CMS根据用户id和该用户与供应商id的关系分割对象的可见性。我目前有一个条件,到目前为止一直有效,它只是这样做: protected void Page_Load(object sender, EventArgs e) { // If the current user is Special Vendor 1, or has a parent Id of Special Vend

我正在开发一个较旧的CMS(C#,Visual Studio 2005,.NET 2.0),该CMS根据用户id和该用户与供应商id的关系分割对象的可见性。我目前有一个条件,到目前为止一直有效,它只是这样做:

protected void Page_Load(object sender, EventArgs e)
    {
        // If the current user is Special Vendor 1, or has a parent Id of Special Vendor 1 then load the "Special Vendor 1" documents
        if ((CurrentUser.Vendor.Id == 3) || (CurrentUser.Vendor.ParentVendor.Id == 3) || (CurrentUser.Vendor.ParentVendor.Id == 1) || (CurrentUser.Vendor.Id == 374) || (CurrentUser.Vendor.ParentVendor.Id == 374))

        {
            hypCatalogAccessLink.NavigateUrl = "documents/SpecialVendor1_Catalog_Access_v3 3_2011_08SV1.pdf";
            hypCatalogAccessLink.Text = "Download Special Vendor 1 Catalog Access";
            hypCatalogAccessLink.Target = "_blank";
        }
        // Another Special Vendor (Special Vendor 2)
        else if ((CurrentUser.Vendor.Name == "Special Vendor 2") || (CurrentUser.Vendor.ParentVendor.Name == "Special Vendor 2"))
        {
            hypCatalogAccessLink.NavigateUrl = "documents/SpecialVendor2_Catalog_Access_v3.3_2011_08_SV2.pdf";
            hypCatalogAccessLink.Text = "Download Special Vendor 2 Catalog Access";
            hypCatalogAccessLink.Target = "_blank";
        }
        else // Use Generic Vendor Catalog as default
        {
            hypCatalogAccessLink.NavigateUrl = "documents/Generic_Catalog_Access_v3 3_2011_08.pdf";
            hypCatalogAccessLink.Text = "Download Generic Catalog Access";
            hypCatalogAccessLink.Target = "_blank";
        }
    }
现在我们有很多特殊供应商1的子供应商,我想做的是从存储过程中提取所有子供应商,当添加子供应商时,存储过程将实时更新结果。但是,我不知道如何将一组整数结果集成到条件语句中。我的第一本能是在第一种情况下使用foreach,但我没有做这类事情的经验。我可以使用 执行官GetAllSV1ChildVendors 这将返回24个供应商的列表,我希望筛选出这些供应商以进行特殊的供应商1可见性访问。
我应该填充数组吗?是否有更直接的方法访问存储过程的结果?任何帮助都很好。谢谢

如果您将供应商ID列表存储在一个列表中,您可以

if (VendorList.Contains(CurrentUser.Vendor.Id) ...

我可以从存储过程的结果填充列表吗?当然可以。只需循环浏览结果并将其添加到列表中即可。您还可以使用LINQ query.VS 2005填充列表,因此这里没有LINQ选项,很遗憾。Contains方法不是LINQ的一部分-list类在.NET 2.0中有此方法:对。我试图指出,您可以使用LINQ来创建列表,而不是手动迭代列表。但是,无论您如何构建列表,都可以使用Contains()检查项目是否存在。