开发者

Column "ColumnName" does not belong to the table

I know there are many questions are posted related to my problem. But I have specific problem in my code.

I have developed an application in asp.net 3.5 and SQL server 2008 and hosted in IIS 6.0 on machine having Windows Server 2003 OS for testing. It is running good for exact 7 users, but for more than 7 users it gives error "Column 'ColumnName' does not belong to the table". And this error comes on any pages frequently. It is also running on local machine but gives error after hosted on IIS. Here is the page structure and code files for your reference.

<asp:Content ID="Content2" ContentPlaceHolderID="AdminMasterContentPlaceHolder" runat="Server">
<div>
    <asp:UpdatePanel ID="upGroups" runat="server" UpdateMode="Conditional">
    开发者_Python百科    <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();
    }

Thanks in advance


I got the solution. I had manually set the command.CommandTimeout=800 at the time of stored procedure execution, which was not working for many users on server. I just commented this line and works fine :) Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜