2011-02-04 80 views
0

我知道有很多問題都貼出來與我的問題有關。但我的代碼中有特定的問題。列「ColumnName」不屬於表

我在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

你在幾個不同的地方綁定網格。錯誤發生在哪裏?它是否僅在一次綁定調用或其中任何一箇中發生?你能跟蹤到達數據庫的實際查詢嗎? – David 2011-02-04 12:41:26

回答

2

我得到了解決。 我在存儲過程執行時手動設置了command.CommandTimeout = 800,這對於服務器上的許多用戶不起作用。我只是評論了這條線,並且工作正常:) 謝謝。

+0

另一個問題是我宣佈靜態連接。 – simplyaarti 2011-02-08 06:52:07