2

我正在做一个项目,我必须在网格视图中返回以下列,并且可以通过 0-7 个过滤器缩小搜索范围。

  • 应用ID
  • 客户名称
  • 项目编号
  • 项目分号
  • 项目名称
  • 应用类型
  • 应用子类型
  • 节点名称
  • 用户名

我可以在我的本地机器上很好地做到这一点,但它返回一个错误,说当我在服务器上运行它时它无法在数据库源中找到 ProjectTitle 字段。其余代码都很好,因为当我从 GridView 中删除 ProjectTitle 列时没有显示错误。以下是我的代码。

ASP

<asp:GridView ID="GridView2" runat="server"
            CellPadding="4" 
            ForeColor="#333333" 
            GridLines="None" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" 
        AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="AppID" HeaderText="AppID" InsertVisible="False" 
                ReadOnly="True" SortExpression="AppID" />
            <asp:BoundField DataField="ClientName" HeaderText="ClientName" 
                SortExpression="ClientName" />
            <asp:BoundField DataField="ProjectNumber" HeaderText="ProjectNo." 
                SortExpression="ProjectNumber" />
            <asp:BoundField DataField="ProjectSubNumber" HeaderText="SubNo." 
                SortExpression="ProjectSubNumber" />
            <asp:BoundField DataField="ProjectTitle" HeaderText="ProjectTitle" 
                SortExpression="ProjectTitle" />
            <asp:BoundField DataField="AppType" HeaderText="AppType" 
                SortExpression="AppType" />
            <asp:BoundField DataField="AppSubType" HeaderText="AppSubType" 
                SortExpression="AppSubType" />
            <asp:BoundField DataField="NodeName" HeaderText="NodeName" 
                SortExpression="NodeName" />
            <asp:BoundField DataField="Username" HeaderText="Username" 
                SortExpression="Username" />
            <asp:CommandField ShowSelectButton="True" ButtonType="Image" 
                SelectImageUrl="~/buttons/png/Select.png" />
        </Columns>
        <AlternatingRowStyle BackColor="White" />
        <FooterStyle BackColor="#D11011" 
                Font-Bold="True" 
                ForeColor="White" />
        <HeaderStyle BackColor="#D11011" 
                Font-Bold="True" 
                ForeColor="White" />
        <PagerStyle BackColor="#FDEBEB" 
                ForeColor="#333333" 
                HorizontalAlign="Center" />
        <RowStyle BackColor="#FDEBEB" 
                ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FDCCCC" 
                Font-Bold="True" 
                ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDEBEB" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FDEBEB" />
        <SortedDescendingHeaderStyle BackColor="#820000" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NeoDyneNewTMS %>" SelectCommand="SELECT [AppID],[ClientName], [ProjectNumber], [ProjectSubNumber], [ProjectTitle], [AppType], [AppSubType], [NodeName], [Username] FROM [PMS_AppRegister],[TMS_Clients],[TMS_ProjectRegister],[PMS_AppTypes],[PMS_AppSubTypes] WHERE [TMS_Clients].[ClientID] = [TMS_ProjectRegister].[ClientID] AND [PMS_AppRegister].[ProjectID] = [TMS_ProjectRegister].[ProjectID] AND [PMS_AppRegister].[AppTypeID] = [PMS_AppTypes].[AppTypeID] AND [PMS_AppRegister].[AppSubTypeID] = [PMS_AppSubTypes].[AppSubTypeID] ORDER BY [AppID] DESC">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="PMS_sch_ds_SELECTAll" 
            runat="server" 
            ConnectionString="<%$ ConnectionStrings:NeoDyneNewTMS %>" 
            SelectCommand="">
        <SelectParameters>
            <asp:ControlParameter ControlID="PMS_sch_ddl_ClientName" 
                    Name="ClientID" 
                    PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="PMS_sch_ddl_ProjectNumber" 
                    PropertyName="SelectedValue" 
                    Name="ProjectNumber" 
                    DefaultValue=null/>
            <asp:ControlParameter ControlID="PMS_sch_ddl_ProjectSubNumber" 
                    Name="ProjectID" 
                    PropertyName="SelectedValue" 
                    DefaultValue=null />
            <asp:ControlParameter ControlID="PMS_sch_ddl_ApplicationType" 
                    Name="AppTypeID" 
                    PropertyName="SelectedValue" 
                    DefaultValue=null />
            <asp:ControlParameter ControlID="PMS_sch_ddl_ApplicationSubType" 
                    Name="AppSubTypeID" 
                    PropertyName="SelectedValue" 
                    DefaultValue=null />
            <asp:ControlParameter ControlID="PMS_sch_tb_NodeName" 
                    Name="NodeName" 
                    PropertyName="Text" 
                    DefaultValue=null />
        </SelectParameters>
    </asp:SqlDataSource>

C#

protected void btnsearch_Click(object sender, ImageClickEventArgs e)
        {
            GridView2.DataSourceID = "PMS_sch_ds_SELECTAll";
            #region Select Command for the Grid View
            //initializes the string for SelectCommand
            string SelectCommand = "";
            if (PMS_sch_ddl_ClientName.SelectedValue != "")
            {
                if (PMS_sch_ddl_ProjectNumber.SelectedValue != "")
                {
                    if (PMS_sch_ddl_ProjectSubNumber.SelectedValue != "")
                    {
                        if (PMS_sch_ddl_ApplicationType.SelectedValue != "")
                        {
                            if (PMS_sch_ddl_ApplicationSubType.SelectedValue != "")
                            {
                                #region Client Name, Project Number, Project Sub Number, Application Type, Application Sub Type, Node Name
                                if (PMS_sch_tb_NodeName.Text != "")
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                                #region Client Name, Project Number, Project Sub Number, Application Type, Application Sub Type
                                else
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                            }
                            else
                            {
                                #region Client Name, Project Number, Project Sub Number, Application Type, Node Name
                                if (PMS_sch_tb_NodeName.Text != "")
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                                #region Client Name, Project Number, Project Sub Number, Application Type
                                else
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            #region Client Name, Project Number, Project Sub Number, Node Name
                            if (PMS_sch_tb_NodeName.Text != "")
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                            #region Client Name, Project Number, Project Sub Number
                            else
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        if (PMS_sch_ddl_ApplicationType.SelectedValue != "")
                        {
                            if (PMS_sch_ddl_ApplicationSubType.SelectedValue != "")
                            {
                                #region Client Name, Project Number, Application Type, Application Sub Type, Node Name
                                if (PMS_sch_tb_NodeName.Text != "")
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                                #region Client Name, Project Number, Application Type, Application Sub Type
                                else
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                            }
                            else
                            {
                                #region Client Name, Project Number, Application Type, Node Name
                                if (PMS_sch_tb_NodeName.Text != "")
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                                #region Client Name, Project Number, Application Type
                                else
                                {
                                    SelectCommand = "SQL";
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            #region Client Name, Project Number, Node Name
                            if (PMS_sch_tb_NodeName.Text != "")
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                            #region Client Name, Project Number
                            else
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    if (PMS_sch_ddl_ApplicationType.SelectedValue != "")
                    {
                        if (PMS_sch_ddl_ApplicationSubType.SelectedValue != "")
                        {
                            #region Client Name, Application Type, Application Sub Type, Node Name
                            if (PMS_sch_tb_NodeName.Text != "")
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                            #region Client Name, Application Type, Application Sub Type
                            else
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                        }
                        else
                        {
                            #region Client Name, Application Type, Node Name
                            if (PMS_sch_tb_NodeName.Text != "")
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                            #region Client Name, Application Type
                            else
                            {
                                SelectCommand = "SQL";
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        #region Client Name, Node Name
                        if (PMS_sch_tb_NodeName.Text != "")
                        {
                            SelectCommand = "SQL";
                        }
                        #endregion
                        #region Client Name
                        else
                        {
                            SelectCommand = @"SELECT    DISTINCT [AppID], [ClientName], [ProjectNumber], [ProjectSubNumber], [ProjectTitle], [AppType], [AppSubType], [NodeName], [PMS_AppRegister].[Username]
                            FROM    [TMS_Clients], [TMS_ProjectRegister], [PMS_AppTypes], [PMS_AppSubTypes],
                                    [PMS_AppRegister], [TMS_EmployeeRegister]
                            WHERE   [TMS_Clients].[ClientID]                    = @ClientID                         AND
                                    [TMS_Clients].[ClientID]                    = [TMS_ProjectRegister].[ClientID]  AND
                                    ([ProjectNumber] IN (SELECT [ProjectNumber]
                                                        FROM    [TMS_ProjectRegister]
                                                        WHERE   [ProjectID] IN  (SELECT [ProjectID]
                                                                                FROM    [PMS_AppRegister])      AND
                                                                [ClientID] = @ClientID))                            AND
                                    ([ProjectSubNumber] IN  (SELECT [ProjectSubNumber]
                                                            FROM    [TMS_ProjectRegister]
                                                            WHERE   [ProjectID] IN  (SELECT [ProjectID]
                                                                                    FROM    [PMS_AppRegister])  AND
                                                                    [ClientID] = @ClientID))                        AND
                                    [PMS_AppRegister].[ProjectID]               = [TMS_ProjectRegister].[ProjectID] AND
                                    [PMS_AppRegister].[AppTypeID]               = [PMS_AppTypes].[AppTypeID]        AND
                                    [PMS_AppSubtypes].[AppTypeID]               = [PMS_AppRegister].[AppTypeID]     AND
                                    [PMS_AppSubTypes].[AppSubTypeID]            = [PMS_AppRegister].[AppSubTypeID]";
                        }
                        #endregion
                    }
                }
            }
            else if (PMS_sch_ddl_ClientName.SelectedValue == "")
            {
                GridView2.DataSourceID = "SqlDataSource1";
            }
            //Lets the datasource's Select Command equal to the correct string
            PMS_sch_ds_SELECTAll.SelectCommand = SelectCommand;
            #endregion
            //GridView1.DataBind();
        }

关于导致这种情况的任何建议?

4

1 回答 1

1

您确定远程数据库包含该字段ProjectTitle吗?

如果您更改 localhost 连接字符串 localhost 以使其使用远程数据库(但仍使用 localhost 项目),您仍然会收到错误吗?(这将确定问题出在代码中,还是在数据库中。)

于 2012-09-19T15:05:23.793 回答