更新时列总计的数据被截断
Data truncated for column total on update
我在 C# 中使用 Telerik,我有 2 个 gridcalculatedcolumn 和 2 个带页脚的 gridtemplatecolumn 和 1 个 button.In 我的 table 列类型是双列。我正在获取值 correct.When 我按下按钮,我正在尝试更新我的数据库上的值,并且在我添加参数的行中,我正在为列总数截断数据。
为什么我会收到此消息以及如何解决此问题?
在 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();
更新
我已经更改了此代码并且正在运行!我将“,”替换为“.”
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];
有没有更简单的方法,或者我必须用 way 来做这个?
我已将“,”替换为“.”正在工作
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];
我在 C# 中使用 Telerik,我有 2 个 gridcalculatedcolumn 和 2 个带页脚的 gridtemplatecolumn 和 1 个 button.In 我的 table 列类型是双列。我正在获取值 correct.When 我按下按钮,我正在尝试更新我的数据库上的值,并且在我添加参数的行中,我正在为列总数截断数据。
为什么我会收到此消息以及如何解决此问题?
在 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();
更新 我已经更改了此代码并且正在运行!我将“,”替换为“.”
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];
有没有更简单的方法,或者我必须用 way 来做这个?
我已将“,”替换为“.”正在工作
string[] words = footernetamount.Split(' ');
footernetamount = words[2];
string[] words3 = footernetamount.Split(',');
footernetamount = words3[0] + "." + words3[1];