The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Gridview with esDatasource - Specified cast is not valid

Last post 07-24-2008, 1:13 AM by rotep. 7 replies.
Sort Posts: Previous Next
  •  07-22-2008, 6:34 AM 10327

    Gridview with esDatasource - Specified cast is not valid

    I have another issue, my other issue concerning esDataSource isn't resolved, this is just another issue.

    I have two NEW projects. One is a website, second a class library (.NET 3.5) containing ES files.

    In project 1 (the website .NET 3.5):

    1. Added references to EntitySpaces, specified Loader in Global.asax / web.config
    2. Added esDatasource to Tabs
    3. Added esDataSource to page -> selected /bin/EC.DLL from class library project for entities
    4. Selected my EntityCollection for the datasource and specified columns
    5. Added Gridview to page and selected Datasource
    6. Specified esSelect event of datasource
    7. When I build and run I get the following error: "Specified cast is not valid"

    Here's the error and code:

    [InvalidCastException: Specified cast is not valid.]
       EntitySpaces.Web.esDataSourceView.FetchTotalRowCount(esDataSourceSelectEventArgs e) +682
       EntitySpaces.Web.esDataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +393
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
       System.Web.UI.WebControls.GridView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +50
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
     

    Code:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="InspectionList._Default" %>
    
    <%@ Register assembly="EntitySpaces.Web" namespace="EntitySpaces.Web" tagprefix="cc1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <cc1:esDataSource ID="esDataSource1" runat="server" AutoPaging="True" 
                AutoSorting="True" />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="PnmAutoKey" DataSourceID="esDataSource1" AllowPaging="True" 
                AllowSorting="True" PageSize="30">
                <Columns>
                    <asp:BoundField DataField="PnmAutoKey" HeaderText="PnmAutoKey" ReadOnly="True" 
                        SortExpression="PnmAutoKey" />
                    <!--- REST OF THE COLUMNS ARE HERE --->
                </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
    </html>
    

    Code:
    Partial Public Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
    
    
        Protected Sub esDataSource1_esSelect(ByVal sender As Object, ByVal e As EntitySpaces.Web.esDataSourceSelectEventArgs) Handles esDataSource1.esSelect
            Dim coll As New EC.BLL.PartsMasterCollection
            coll.LoadAll()
            e.Collection = coll
        End Sub
    End Class
  •  07-22-2008, 6:47 AM 10329 in reply to 10327

    Re: Gridview with esDatasource - Specified cast is not valid

    Try this:

    Code:
        Protected Sub esDataSource1_esSelect(ByVal sender As Object, ByVal e As EntitySpaces.Web.esDataSourceSelectEventArgs) Handles esDataSource1.esSelect
            Dim coll As New EC.BLL.PartsMasterCollection
            e.Collection = coll
        End Sub
    

    When you have either AutoPaging or AutoSorting set to true the esDataSource will load the data for you, you must not load the collection.

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  07-23-2008, 1:34 AM 10344 in reply to 10329

    Re: Gridview with esDatasource - Specified cast is not valid

    This doesn't work Mike... I've tried on my other project using only one class... Same error: Specified cast is not valid.

    /Solution_1
    /Solution_1/InspectionList/            << this is the web project
    /Solution_1/InspectionList_BLL/     << this is the class library with my generated class

     

    This is the Oracle table which is used:

    Code:
      CREATE TABLE "INTRANETUSER"."INTRANET_APU_INSPECTION" 
       (	"SI_NUMBER" NVARCHAR2(10), 
    	"PNM_MAIN" NUMBER(8,0), 
    	"PNM_AUTO_KEY" NUMBER(8,0), 
    	"PN" NVARCHAR2(100), 
    	"DESCRIPTION" NVARCHAR2(250), 
    	"INSPECTION_TYPE" CHAR(2 CHAR), 
    	"INSPECTION_NOTES" NVARCHAR2(2000), 
    	"TIME" CHAR(8 CHAR), 
    	"SERIAL" VARCHAR2(100 BYTE), 
    	"QTY" NUMBER DEFAULT 1, 
    	"SB_TYPE" VARCHAR2(25 BYTE)
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "TBS_INTRANETUSER" ;

     

  •  07-23-2008, 1:39 AM 10345 in reply to 10344

    Re: Gridview with esDatasource - Specified cast is not valid

    I just tried selecting only one column (tried all) in the esDataSource. This doesn't work either.
  •  07-23-2008, 7:05 AM 10348 in reply to 10345

    Re: Gridview with esDatasource - Specified cast is not valid

    The esDataSource TotalRowCount is an int, but Oracle and MySQL will return a long for CountAll. Until we get a fix in, you cannot rely on esDataSource automatically calculating the TotalRowCount, but must set it as described in the original Blog post. Here is a modified version of the posted Page_Load which will convert, rather than cast TotalRowCount.

    Code:
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            Employees emp = new Employees();
            emp.Query.es.CountAll = true;
            emp.Query.es.CountAllAlias = "Count"
            if (emp.Query.Load())
            {
                esDataSrc.TotalRowCount = Convert.ToInt32(emp.GetColumn("Count"));
            } 
    
            gridView.Sort(EmployeesMetadata.PropertyNames.LastName, SortDirection.Ascending);
        }
    }

     


    David Neal Parsons
    www.entityspaces.net
  •  07-23-2008, 1:10 PM 10354 in reply to 10348

    Re: Gridview with esDatasource - Specified cast is not valid

    I will try as soon as i get back at work. Thanks
  •  07-23-2008, 7:19 PM 10360 in reply to 10354

    Re: Gridview with esDatasource - Specified cast is not valid

    We are changing the esDataSource to do a Convert.ToInt32() rather than an (int) cast which should fix this. It will be included in our 1st ES2008 maintenance release.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  07-24-2008, 1:13 AM 10363 in reply to 10360

    Re: Gridview with esDatasource - Specified cast is not valid

    Thx David, works like a charm.

View as RSS news feed in XML