在DataGridview中,我有Letter Grade
、Minimum Letter Grade
和Maximum Letter Grade
(例如Letter Grade = A-
、Minimum Letter Grade = 85,00
和Maximum Letter Grade = 89,99
)
例如,如果我将Minimum Letter Grade = 85,00
更新为85,99
,它会将其另存为85,00
。
我如何才能像85,99
那样更新它?
数据库中Letter Grade Min
和Letter Grade Max
的数据类型是DECIMAL(4,2)
。
public static void updateGradeRanges(string LetterGrd, double LgMin, double LgMax)
try
{
string cmdText = "UPDATE grade_range SET LG_MIN='" + LgMin + "', LG_MAX='" + LgMax + "' WHERE Letter_Grade='" + LetterGrd + "';";
MySqlCommand cmd = new MySqlCommand(cmdText, DB.Conn);
int result = cmd.ExecuteNonQuery();
}
我向这样的函数发送参数:
updateGradeRanges(LetterGrade,Convert.ToDouble(txtMinGrade.Text),Convert.ToDouble(txtMaxGrde.Text));
<asp:UpdatePanel ID="UpdatePanel1" runat="server" Visible="true">
<ContentTemplate>
<asp:GridView ID="Grades_GridView" runat="server" BackColor="White" BorderColor="White"
BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
GridLines="None" AutoGenerateColumns="False"
DataKeyNames="Letter_Grade"
onrowcancelingedit="Grades_GridView_RowCancelingEdit"
onrowediting="Grades_GridView_RowEditing"
onrowupdating="Grades_GridView_RowUpdating"
onrowdeleting="Grades_GridView_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="Letter Grade" SortExpression="Letter_Grade">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Letter_Grade") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minimum Letter Grade" SortExpression="LG_MIN">
<EditItemTemplate>
<asp:TextBox ID="txtMinGrade" runat="server" Text='<%# Bind("LG_MIN") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("LG_MIN") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maximum Letter Grade" SortExpression="LG_MAX">
<EditItemTemplate>
<asp:TextBox ID="txtMaxGrade" runat="server" Text='<%#Bind("LG_MAX") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("LG_MAX") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButtonUpdateGrade" runat="server" CommandName="Update" CausesValidation="True"><span class="link_span_small">Update</span></asp:LinkButton>
<asp:LinkButton ID="LinkButtonCancelGrade" runat="server" CommandName="Cancel" CausesValidation="True"><span class="link_span_small">Cancel</span></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="ImageButtonEditGrade" runat="server" CausesValidation="False"
CommandName="Edit" ToolTip="Edit" ImageUrl="~/Images/edit.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
最佳答案
从sql update语句中删除单引号。
关于c# - 如何使用小数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16243901/