I am using Telerik with C# and i have 2 gridcalculatedcolumn and 2 gridtemplatecolumn with footer and 1 button.In my table the columns types are double. I am getting the values correct.When I press the button i am trying to update the values on my db and i am getting Data truncated for column total in the line that I add the parameters.

Why I am getting this messages and how I can fix this?

IN aspx:

 <telerik:GridTemplateColumn Aggregate="Sum"  FooterText="Total Discount: " DataField="DiscAmount" DataType="System.Decimal" FilterControlAltText="Filter DiscAmount column" HeaderText="DiscAmount(€)" SortExpression="DiscAmount" UniqueName="DiscAmount">
                    <EditItemTemplate>
                        <asp:TextBox ID="DiscAmountTextBox" runat="server" Text='<%# Bind("DiscAmount") %>' AutoPostBack="true"  OnTextChanged="DiscAmount_TextChanged" ></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="DiscAmountLabel" runat="server" Text='<%# Eval("DiscAmount") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
   <telerik:GridTemplateColumn Aggregate="Sum"  FooterText="Total NetAmount: "    DataField="NetAmount" DataType="System.Decimal" FilterControlAltText="Filter  NetAmount column" HeaderText="NetAmount(€)" SortExpression="NetAmount" UniqueName="NetAmount">
                    <EditItemTemplate>
                     <asp:TextBox ID="NetAmountTextBox" runat="server" Text='<%# Bind("NetAmount") %>' Enabled="false" ></asp:TextBox>
                 </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

          <telerik:GridCalculatedColumn HeaderText="Total VAT" UniqueName="TotalVAT" DataType="System.Decimal" DataFormatString="{0:F}"
                    DataFields="price,VAT" FooterText="Total Vat : "  Expression="({0}*({1}/100))" 
                    Aggregate="Sum" />
          <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Decimal" DataFormatString="{0:F}"
                    DataFields="price,DiscAmount,VAT" Expression="(({0}-{1})*({2}/100))+({0}-{1})" FooterText="Total : "
                    Aggregate="Sum" />

aspx.cs:

  GridFooterItem footeritem = (GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0];
                double footervat = Convert.ToDouble( footeritem["TotalVAT"].Text);
                string footerprice =  footeritem["TotalPrice"].Text;
                string footerdisc = footeritem["DiscAmount"].Text;
                string footernetamount = footeritem["NetAmount"].Text;

            string[] words = footernetamount.Split(' ');
            footernetamount = words[2];
            string[] words2 = footerdisc.Split(' ');
            footerdisc = words[2];
            string insdocheader = "UPDATE mytable SET Total=@netAmount, AmountDue=@footerprice,VAT=@footervat,Discount=@footerdisc WHERE DocNo=@docnoparam and DocStatus=@docstatusparam";


               MySqlCommand cmd3 = new MySqlCommand(insdocheader, con2);
               cmd3.Parameters.AddWithValue("docnoparam", DocNoTxtBox.Text);
               cmd3.Parameters.AddWithValue("docstatusparam", 2);
              con2.Open();

            cmd3.Parameters.AddWithValue("netAmount", footernetamount);
            cmd3.Parameters.AddWithValue("footerprice", footerprice);
            cmd3.Parameters.AddWithValue("footervat", footervat);
            cmd3.Parameters.AddWithValue("footerdisc", footerdisc);
                cmd3.ExecuteNonQuery();

Related posts

Recent Viewed