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

Sum is not supported for type "System.Object"

1 Answer 628 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajeev
Top achievements
Rank 1
Rajeev asked on 18 Dec 2012, 11:41 PM
I am getting this error

Sum is not supported for type "System.Object"

For testing purposes i am using one table only.

The table Design is

ProductID autonumber
ID  int
ProductName Varchar(100)
Price Varchar(150)

Then i also added DataType=DataType=System.Decimal then i get an error

A value of type 'String' cannot be converted to type 'Decimal?'


This is my ASPX code
 
<asp:Content ID="Content2" ContentPlaceHolderID="contentplaceholder1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
        EnableRoundedCorners="false" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="RadGrid1"
        Width="100%" AllowSorting="True"
        ShowFooter="True" PageSize="15" AllowPaging="True" AllowMultiRowSelection="True" ShowChooser="true"
        runat="server" GridLines="None" AutoGenerateColumns="False" CellSpacing="0" DataSourceID="ObjectDataSource1">
        <MasterTableView Width="100%" Summary="RadGrid table" RetrieveAllDataFields="false"
            DataSourceID="ObjectDataSource1">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn DataField="Productid" HeaderText="Productid" DataType="System.Int32"
                    SortExpression="Productid">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="id" HeaderText="id" DataType="System.Int32" FilterControlAltText="Filter id column"
                    SortExpression="id" UniqueName="id">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" FilterControlAltText="Filter ProductName column"
                    SortExpression="ProductName" UniqueName="ProductName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Price" HeaderText="Price" SortExpression="Price" Aggregate="Sum" FooterText="Total price: ">
                </telerik:GridBoundColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetListProduct"
        TypeName="Business.ProductManager"></asp:ObjectDataSource>
</asp:Content>




 
/////////////////////////////////////////////////////////////////////////
 public static ProductList GetListProduct()
        {
            ProductList tempList = null;
 
 
            string sql = "SELECT * from Product";
            //using (SqlConnection myConnection = new SqlConnection(AppConfig.ConnectionString))
            using (SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["NLayer"].ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand(sql, myConnection))
                {
                    myConnection.Open();
 
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new ProductList();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecordProduct(myReader));
                            }
                        }
                        myReader.Close();
                    }
                }
                return tempList;
 
            }
        }
 
 
 private static Product FillDataRecordProduct(IDataRecord myDataRecord)
        {
            Product myUserTracking = new Product();
 
            myUserTracking.Productid = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Productid"));
            myUserTracking.id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("id"));
            myUserTracking.ProductName = myDataRecord.GetString(myDataRecord.GetOrdinal("ProductName"));
 
            myUserTracking.Price = myDataRecord.GetString(myDataRecord.GetOrdinal("Price"));
 
 
            return myUserTracking;
        }

         



1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 21 Dec 2012, 01:20 PM
Hello Rajeev,

Currently, you are using a string type field for the Price column. Please note that Sum aggregate is supported only for numeric fields. Change the field to a numeric type and let me know about the result.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or