I am working on a project where I must return the following columns in a gridview, and search can be narrowed down by 0-7 filters.
I am able to do this fine on my local machine, but it returns an error saying that it cannot find the ProjectTitle Field in the database source when I run it on the server. The rest of the code is fine, as there is no error displayed when I remove the ProjectTitle column from the GridView. The following is my code.
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();
}
Any suggestions on what would be causing this?
Are you sure the remote database contains the field ProjectTitle
?
If you change the localhost connection string localhost so it uses the remote database (but still using the localhost project) do you still get the error? (This will determine whether the problem lies in the code, or in the database.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.