[英]GridView: Database error when running on server, works fine on localhost
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. 我正在一个项目中,我必须在gridview中返回以下列,并且可以通过0-7过滤器缩小搜索范围。
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. 我可以在本地计算机上完成此操作,但是它返回错误,提示我在服务器上运行它时无法在数据库源中找到ProjectTitle字段。 The rest of the code is fine, as there is no error displayed when I remove the ProjectTitle column from the GridView.
其余的代码很好,因为当我从GridView中删除ProjectTitle列时没有显示错误。 The following is my code.
以下是我的代码。
ASP 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# 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
? 您确定远程数据库包含字段
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? 如果更改localhost连接字符串localhost,以便它使用远程数据库(但仍使用localhost项目),您是否还会收到错误消息? (This will determine whether the problem lies in the code, or in the database.)
(这将确定问题是在代码中还是在数据库中。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.