列“ColumnName”不属于该表

时间:2011-02-04 12:25:29

标签: c# asp.net sql-server-2008 iis

我知道有很多问题与我的问题有关。但我的代码中存在特定问题。

我在asp.net 3.5和SQL Server 2008中开发了一个应用程序,并在具有Windows Server 2003操作系统的机器上的IIS 6.0中进行测试。对于确切的7个用户来说它运行良好,但是对于超过7个用户,它给出了错误“Column'ColumnName'不属于该表”。而这个错误经常出现在任何页面上。它也在本地计算机上运行,​​但在IIS上托管后出错。 以下是页面结构和代码文件供您参考。

<asp:Content ID="Content2" ContentPlaceHolderID="AdminMasterContentPlaceHolder" runat="Server">
<div>
    <asp:UpdatePanel ID="upGroups" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Panel ID="pnlGroups" runat="server" Width="90%">
                <table>
                    <tr>
                        <td align="left">
                            <asp:Label ID="lblGroups" runat="server" Text="Groups" class="altheading"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td><asp:Label ID="lblshow" runat="server" Text="" ForeColor="Red" CssClass="altlabel"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Button ID="imgAddGroup" runat="server" Text="Add Group" OnClick="imgAddGroup_Click" />
                            <asp:Button ID="imgdeleteGroup" runat="server" Text="Delete" OnClick="imgdeleteGroup_Click"
                                CausesValidation="False" OnClientClick="javascript:return confirm('Do you want to delete the record?');" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:GridView ID="grdviewGroups" runat="server" AutoGenerateColumns="False" DataKeyNames="GroupID"
                                AllowPaging="True" AllowSorting="True" OnDataBound="grdviewGroups_DataBound"
                                OnRowCommand="grdviewGroups_RowCommand" Width="500px" OnPageIndexChanging="grdviewGroups_PageIndexChanging"
                                OnSelectedIndexChanged="grdviewGroups_SelectedIndexChanged1" CssClass="gridtable">
                                <EmptyDataTemplate>
                                    <asp:Label ID="lblemptygridmsg" runat="server" Text="There is no data to show"></asp:Label></EmptyDataTemplate>
                                <Columns>
                                    <asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                        <EditItemTemplate>
                                            <asp:CheckBox ID="chkGroups" runat="server" />
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkGroups" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="RowNumber" HeaderText="Id" ItemStyle-HorizontalAlign="Center" />
                                    <asp:BoundField DataField="GroupID" Visible="False" />
                                    <asp:TemplateField HeaderText="Group Code">
                                        <ItemStyle HorizontalAlign="Left" ForeColor="#0033CC" />
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkGroupCode" runat="server" CommandName="GroupCode" Text='<%# Eval("GroupCode") %>'
                                                CommandArgument='<%# Eval("GroupID") %>' Font-Underline="True" ForeColor="#0033CC"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Group Name">
                                        <ItemStyle HorizontalAlign="left" ForeColor="#0033CC" />
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkGroupName" runat="server" CommandName="GroupName" Text='<%# Eval("GroupName") %>'
                                                CommandArgument='<%# Eval("GroupID") %>' Font-Underline="True" ForeColor="#0033CC"></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="GroupDescription" HeaderText="Description" />
                                </Columns>
                            </asp:GridView>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

public partial class Admin_Groups : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     ValidateUserLogin.UserLoginRequired();
        if (!IsPostBack)
        {
            //on page load, show GroupGrid
            BindGGrid();
        }

    }
    protected void grdviewGroups_DataBound(object sender, EventArgs e)
    {

    }
    //show GroupGrid
    public void BindGGrid()
    {
        Groups gps = new Groups();
        grdviewGroups.DataSource = gps.ShowAllGroups();
        grdviewGroups.DataBind();
    }

    protected void grdviewGroups_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        Groups gps = new Groups();
        //int id = Convert.ToInt32(grdviewGroups.DataKeys[row.RowIndex].Value);
        if (e.CommandName == "GroupCode")
        {
            Response.Redirect("AddEditGroups.aspx?ID=" + gps.Encryptid((e.CommandArgument.ToString())));
        }

        else if (e.CommandName == "GroupName")
        {
            Response.Redirect("AddEditGroups.aspx?ID=" + gps.Encryptid((e.CommandArgument.ToString())));
        }
    }
    protected void grdviewGroups_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
  protected void imgdeleteGroup_Click(object sender, EventArgs e)
    {
        // to delete group data by groupid
        string gpsid = string.Empty;
        int id;
        Groups gps = new Groups();

        foreach (GridViewRow row in grdviewGroups.Rows)
        {
            CheckBox checkbox = (CheckBox)row.FindControl("chkGroups");
            if (checkbox.Checked)
            {
                id = Convert.ToInt32(grdviewGroups.DataKeys[row.RowIndex].Value);
                gpsid = gpsid + id + ",";
            }
        }
        //string str1 = gpsid;
        //gps.DeleteGroup(str1);
        //grdviewGroups.DataSource = gps.ShowAllGroups();
        //grdviewGroups.DataBind();
        string str1 = gpsid;
        int a=gps.DeleteGroup(str1);
        if (a == 1)
        {
            lblshow.Text = "You can not delete this record because there is reference in database"; 
        }
        else
        {
            if (gpsid == "")
            {
                lblshow.Text = "Please select the record that you want to delete!";
            }
            else
            {
                lblshow.Text = "Record is deleted";
            }


        }
        grdviewGroups.DataSource = gps.ShowAllGroups();
        grdviewGroups.DataBind();
    }
    protected void imgAddGroup_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddEditGroups.aspx");
    }
    protected void grdviewGroups_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdviewGroups.PageIndex = e.NewPageIndex;
        BindGGrid();
    }

提前致谢

1 个答案:

答案 0 :(得分:2)

我得到了解决方案。 我在存储过程执行时手动设置了command.CommandTimeout = 800,这对服务器上的许多用户都没有用。我只是评论了这一行并且工作得很好:) 感谢。