This is a migrated thread and some comments may be shown as answers.

ERROR: [column] is neither a DataColumn nor DataRelation for [table]

9 Answers 1300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sid
Top achievements
Rank 1
Sid asked on 25 Mar 2009, 10:57 PM
Version: Q1 2009 (.NET 3.5)
Language: C#
Dev: VS 2005

I have a page that allows the user to select a database table from a dropdown list and display the data in a RadGrid.  The RadGrid is set to automatically generate columns and allow scrolling and sorting.  If I switch between tables without sorting, I get no errors.  However, if I pick a table, sort on a column, and then select another table to view, I get a runtime error of "[column] is neither a DataColumn nor a DataRelation for table [tablename]."   Code snippet below. 

protected void RefreshData() 
        { 
          DataSet  ds; 
          string   query; 
          string   tableName; 
           
          // clear old data 
          UserMsg.Text = ""
          Cache.Remove("wadv_ds"); 
          clearGrid(); 
 
          // get data 
          tableName = cbTableList.SelectedValue; 
          query = @"SELECT * FROM " + tableName; 
          ds = dba.ReadData(query, tableName); 
 
          // update grid 
          if (ds == null) 
            { 
              UserMsg.Text = "DataSet is null."
            } 
           else if (ds.Tables[0].Rows.Count == 0) 
            { 
              UserMsg.Text = "Table has no data."
            } 
           else 
            { 
              Cache["wadv_ds"] = ds.Tables[0]; 
 
              rgData.DataSource = ds.Tables[0]; 
              rgData.DataBind();                               //  <=== ERROR OCCURS HERE 
            } 
        } 
        //------------------------------------------------------------------------- 
    protected void clearGrid() 
    { 
      rgData.DataSource = null
      rgData.DataBind(); 
      rgData.Columns.Clear(); 
    } 
    //------------------------------------------------------------------------- 

Any help resolving this would be greatly appreciated.  Thanks.

9 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 30 Mar 2009, 01:32 PM
Hi Gary,

Could you post your complete aspx and code-behind.

Thank you.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sid
Top achievements
Rank 1
answered on 30 Mar 2009, 03:40 PM

Thanks for your response.   Here is the ASPX code:

<%@ Page language="c#" MasterPageFile="~/RestrictedArea/Menu.Master" Codebehind="WADV.aspx.cs" AutoEventWireup="True" Inherits="DDS_Web.RestrictedArea.WADV" Title="Data Viewer" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">  
      <align="center">  
        <asp:label id="Label1" runat="server" CssClass="PageTitleAdminOnly">Website Administration - Data Viewer</asp:label><BR>  
        <asp:Label id="Label2" runat="server" CssClass="PageTitleAdminOnlyWarning">This page for authorized personnel only!</asp:Label></P>  
      <DIV align="left">  
        <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="1">  
          <TR> 
            <TD height="10%" style="width: 1031px">  
              <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" border="0">  
                <TR> 
                  <TD width="20%">  
                    <asp:Label id="Label3" runat="server" CssClass="LabelText">Database Table: </asp:Label></TD>  
                  <TD> 
                    <asp:DropDownList id="cbTableList" runat="server">  
                      <asp:ListItem Value="DDS_Announcements">Announcements</asp:ListItem> 
                      <asp:ListItem Value="DDS_Ann2GroupXref">Announcement - Group Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_Ann2ProgramXref">Announcement - Program Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_GroupAccessRequestHistory">Group Access Request History</asp:ListItem> 
                      <asp:ListItem Value="DDS_GroupAccessRequests">Group Access Requests</asp:ListItem> 
                      <asp:ListItem Value="DDS_Groups">Groups</asp:ListItem> 
                      <asp:ListItem Value="DDS_Item">Items</asp:ListItem> 
                      <asp:ListItem Value="DDS_Item2GroupXref">Item - Group X ref</asp:ListItem> 
                      <asp:ListItem Value="DDS_Item2ProgramXref">Item - Program Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_ItemCategories">Item Categories</asp:ListItem> 
                      <asp:ListItem Value="DDS_ItemHistory">Item History</asp:ListItem> 
                      <asp:ListItem Value="DDS_Program">Programs</asp:ListItem> 
                      <asp:ListItem Value="DDS_UserRequests">Program Access Requests</asp:ListItem> 
                      <asp:ListItem Value="DDS_UserReqXref">Program Access Request Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_Program2GroupXref">Program - Group Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_ProgramTree">Program Tree</asp:ListItem> 
                      <asp:ListItem Value="DDS_Reports">Reports</asp:ListItem> 
                      <asp:ListItem Value="DDS_User2ReportXref">Report - User Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_ReportDataGroups">Report Data Groups</asp:ListItem> 
                      <asp:ListItem Value="DDS_ReportDataGroupXref">Report Data Group Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_User2ReportDataGroupXref">Report Data Group - User Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_User2GroupXref">User - Group Xref</asp:ListItem> 
                      <asp:ListItem Value="DDS_UserPrefs">User Preferences</asp:ListItem> 
                      <asp:ListItem Value="DDS_Users">Users</asp:ListItem> 
                      <asp:ListItem Value="DDS_UsersActivity">Users Activity</asp:ListItem> 
                      <asp:ListItem Value="DDS_UsersDtl">Users Details</asp:ListItem> 
                      <asp:ListItem Value="DDS_UsersHistory">Users History</asp:ListItem> 
                      <asp:ListItem Value="DDS_UsersPasswords">Users Passwords</asp:ListItem> 
                      <asp:ListItem Value="DDS_WCRS">WCRs</asp:ListItem> 
                    </asp:DropDownList></TD>  
                  <TD width="20%">  
                    <align="center">  
                      <asp:Button id="btnRefresh" runat="server" Text="Refresh Data" onclick="btnRefresh_Click"></asp:Button></P>  
                  </TD> 
                </TR> 
              </TABLE> 
              &nbsp;  
            </TD> 
          </TR> 
          <TR> 
            <TD height="80%" style="width: 1031px">  
              &nbsp;<telerik:RadGrid ID="rgData" runat="server" AllowSorting="True" GridLines="None" 
                Skin="Web20" OnNeedDataSource="rgData_NeedDataSource">  
                <MasterTableView CellSpacing="-1">  
                  <RowIndicatorColumn> 
                    <HeaderStyle Width="20px" /> 
                  </RowIndicatorColumn> 
                  <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px" /> 
                  </ExpandCollapseColumn> 
                </MasterTableView> 
                <ClientSettings> 
                  <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                </ClientSettings> 
              </telerik:RadGrid></TD>  
          </TR> 
          <TR> 
            <TD height="10%" style="width: 1031px">  
              <asp:Label id="UserMsg" runat="server" CssClass="ErrorText"></asp:Label></TD>  
          </TR> 
        </TABLE> 
        <br> 
        </DIV> 
</asp:Content> 
 

Here is the C# code:
using System;  
using System.Collections;  
using System.ComponentModel;  
using System.Configuration;  
using System.Data;  
using System.Drawing;  
using System.Web;  
using System.Web.SessionState;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.HtmlControls;  
using DDS_Web.Core;  
 
namespace DDS_Web.RestrictedArea  
{  
    /// <summary> 
    /// Summary description for WADV.  
    /// </summary> 
    public partial class WADV :  RestrictedPage //System.Web.UI.Page  
    {  
      
      protected DbAccess dba;     
        
        protected void Page_Load(object sender, System.EventArgs e)  
        {  
            sessionMgr = new SessionMgr(Session);  
              
      //if (!sessionMgr.IsWebAdmin())  
      //  {  
      //    Response.Redirect("MainCourtyard.aspx");  
      //  }  
                
            UserMsg.Text = "";  
              
            if (!Page.IsPostBack)  
              {  
          Cache.Remove("wadv_ds");  
          clearGrid();  
          CreateDba();  
              }  
             else  
              {  
                bool bRecreate = false;  
                try  
                  {  
                    dba = (DbAccess)Cache["wadv_dba"];  
                    if (dba == null)  
                      bRecreate = true;  
                  }  
                catch  
                  {  
                    bRecreate = true;  
                  }  
                    
                if (bRecreate)  
                  CreateDba();  
              }  
        }  
        //-------------------------------------------------------------------------  
        protected void CreateDba()  
        {  
          string dbcs;  
            
            dbcs = ConfigurationSettings.AppSettings["SqlConnectionString"];  
            dba = new DbAccess(dbcs);  
              
            Cache["wadv_dba"] = dba;  
        }  
        //-------------------------------------------------------------------------  
    protected void clearGrid()  
    {  
      rgData.DataSource = null;  
      rgData.DataBind();  
      rgData.Columns.Clear();  
    }  
    //-------------------------------------------------------------------------  
        protected void btnRefresh_Click(object sender, System.EventArgs e)  
        {  
        RefreshData();  
        }  
        //-------------------------------------------------------------------------  
        protected void RefreshData()  
        {  
          DataSet  ds;  
          string   query;  
          string   tableName;  
            
      // clear old data  
            UserMsg.Text = "";  
      Cache.Remove("wadv_ds");  
      clearGrid();  
 
            // get data  
      tableName = cbTableList.SelectedValue;  
            query = @"SELECT * FROM " + tableName;  
            ds = dba.ReadData(query, tableName);  
 
      // update grid  
            if (ds == null)  
              {  
                UserMsg.Text = "DataSet is null.";  
 
          //rgData.DataSource = null;  
          //rgData.DataBind();  
              }  
             else if (ds.Tables[0].Rows.Count == 0)  
              {  
                UserMsg.Text = "Table has no data.";  
 
          //rgData.DataSource = null;  
          //rgData.DataBind();  
              }  
             else  
              {  
          Cache["wadv_ds"] = ds.Tables[0];  
 
          rgData.DataSource = ds.Tables[0];  
          rgData.DataBind();   
              }  
        }  
        //-------------------------------------------------------------------------  
    protected void rgData_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
      try  
        {  
          DataTable dt;  
 
          dt = (DataTable)Cache["wadv_ds"];  
          rgData.DataSource = dt;  
        }  
      catch   
        {  
          UserMsg.Text = "Read from cache failed.  Please click Refresh button.";  
        }  
    }  
    //-------------------------------------------------------------------------  
     
        #region Web Form Designer generated code  
        override protected void OnInit(EventArgs e)  
        {  
            //  
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.  
            //  
            InitializeComponent();  
            base.OnInit(e);  
        }  
          
        /// <summary> 
        /// Required method for Designer support - do not modify  
        /// the contents of this method with the code editor.  
        /// </summary> 
        private void InitializeComponent()  
        {      
 
    }  
        #endregion  
 
      
 
     
 
          
 
          
    }  
}  
 

If you need anything else, please let me know.

Thanks,
Gary
0
Tsvetoslav
Telerik team
answered on 02 Apr 2009, 06:51 AM
Hi Gary,

I followed  your code in a sample project of mine but could not reproduce the problem you are experiencing.

In this case, I'd ask you to open a formal support ticket and send us a runnable example along with the database and the dataaccess layer so that we can debug it and locate the issue.

Thank you.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sid
Top achievements
Rank 1
answered on 06 Apr 2009, 09:17 PM
I have opened a support ticket and uploaded the relevant files.  Ticket # 203408.
0
Accepted
Tsvetoslav
Telerik team
answered on 08 Apr 2009, 11:35 AM
Hi Gary,

Thanks for opening up the support ticket.
Herein I am attaching the sample of my colleague contained in his reply to your support ticket so that other people might benefit from it if they encounter a similar problem.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Sid
Top achievements
Rank 1
answered on 08 Apr 2009, 05:25 PM
Thank you!  I updated my code with your modifications and it works!
0
varsha Motwani
Top achievements
Rank 1
answered on 30 Apr 2010, 08:01 AM
Can you please elloborate wahat changes we need to do.I am also facing similar problem .I am dynamically generating the radgrid.
0
Sid
Top achievements
Rank 1
answered on 03 May 2010, 10:43 PM
In the ASPX file, bold text was added:
<telerik:RadGrid ...>

 

<MasterTableView EnableColumnsViewState="false" CellSpacing="-1">
...
</telerik:RadGrid>

In the C# file, the basic code is outlined below:

protected void btnRefresh_Click(object sender, System.EventArgs e)  
{  
  RefreshData();  
  rgData.MasterTableView.SortExpressions.Clear();  
  rgData.Rebind();   
}  
//-------------------------------------------------------------------------  
protected void RefreshData()  
{  
  DataSet  ds;  
  string   query;  
  string   tableName;  
        
  // clear old data  
  Cache.Remove("cache_name");  
 
  // get data  
  ds = [Get data here]  
    
  // update grid  
  if (ds == null)  
    {  
      // error message/handling  
    }  
   else if (ds.Tables[0].Rows.Count == 0)  
    {  
      // user message/error handling  
    }  
   else 
    {  
      Cache["cache_name"] = ds.Tables[0];  
    }  
}  
//-------------------------------------------------------------------------  
protected void rgData_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
{  
      try 
        {  
          DataTable dt;  
 
          dt = (DataTable)Cache["cache_name"];  
          rgData.DataSource = dt;  
        }  
      catch   
        {  
          // error message/handling  
        }  
}  
//------------------------------------------------------------------------- 

Hope this helps.  This code was originally written for a late 2008 or early 2009 version of the controls.
0
Swapna
Top achievements
Rank 1
answered on 16 Sep 2011, 03:43 PM
Can anyone explain the cause of this Error. We are also getting the same issue, but not able to trace the exact reason. I am trying to handle this exception from code behind but not even able to trace it. We even tried the above given solutions.

After clearing AppPool this issue was resolved previously. But this time we want to trace this issue, can any one help us please.

Tags
Grid
Asked by
Sid
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Sid
Top achievements
Rank 1
varsha Motwani
Top achievements
Rank 1
Swapna
Top achievements
Rank 1
Share this question
or