2

グリッドビューで次の列を返す必要があるプロジェクトに取り組んでおり、検索は0〜7個のフィルターで絞り込むことができます。

  • AppID
  • ClientName
  • プロジェクト番号
  • ProjectSubNo。
  • プロジェクト名
  • AppType
  • AppSubType
  • NodeName
  • ユーザー名

ローカルマシンでこれを正常に実行できますが、サーバーで実行すると、データベースソースに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 に答える