3

在 DataGridview 中,我的字段是Letter Grade,Minimum Letter GradeMaximum Letter Grade(例如Letter Grade = A-, Minimum Letter Grade = 85,00and Maximum Letter Grade = 89,99)

例如,如果我对其进行更新Minimum Letter Grade = 85,0085,99则将其保存为85,00.

我怎样才能完全更新它85,99

Letter Grade MinLetter 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>&nbsp;
              <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>
4

1 回答 1

0

从您的 sql update 语句中删除单引号。

于 2013-04-26T21:05:51.660 回答