-1
--source code--
<table style="border: thin ridge #000000; width: 72%; margin-top: 21px; margin-left: 243px;"
bgcolor="#CCCCFF">
<tr align="center">
<td class="style11">
</td>
<td class="style2">
</td>
<td class="style4">
</td>
<td class="style17">
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style15" align="center">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="0.125"
oncheckedchanged="CheckBox1_CheckedChanged1" CausesValidation="True" />
</td>
<td class="style16" align="center">
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Text="0.25"
oncheckedchanged="CheckBox2_CheckedChanged" CausesValidation="True" />
</td>
<td class="style18">
</td>
</tr>
<tr align="center" style="background-color:Fuchsia;">
<td class="style11">
L</td>
<td class="style2">
B
</td>
<td class="style4">
W</td>
<td class="style17">
N</td>
</tr>
<tr align="center" style="background-color:Fuchsia;">
<td class="style12">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="115px" TabIndex="1" ></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style7">
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server" Width="115px" TabIndex="2"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style9">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox3" runat="server" Width="115px" AutoPostBack="True"
ontextchanged="TextBox3_TextChanged" TabIndex="3"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style19">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox4" runat="server" Width="115px" TabIndex="4"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr><td class="style13"></td><td class="style8">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</td>
<td class="style10">
</td><td class="style20"></td></tr>
<tr align="right" style="background-color:snow;">
<td class="style3" colspan="2">
<asp:TextBox ID="TextBox7" runat="server" Width="142px"></asp:TextBox>
</td>
<td align="left" class="style4">
Price</td>
<td class="style17">
</td>
</tr>
<tr align="center">
<td class="style3" colspan="2">
</td>
<td align="left" class="style4">
</td>
<td class="style17">
</td>
</tr>
<tr align="center">
<td class="style3" colspan="2" align="right">
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
Text="Calculate" CausesValidation="False" />
</td>
<td align="left" colspan="2">
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Calculate" />
<input type="hidden" runat="server" id="hid" /></td>
</tr>
</table>
--code behind--
protected void Button1_Click(object sender, EventArgs e)
{
l = Convert.ToDecimal(TextBox1.Text);
b = Convert.ToDecimal(TextBox2.Text);
w = Convert.ToDecimal(TextBox3.Text);
n = Convert.ToDecimal(TextBox4.Text);
price = Convert.ToDecimal(TextBox7.Text);
avg = (l * b * w * n)/4;
tot = avg * price;
try
{
string ins = "insert into cal_tbl(l,b,w,n,price,average,total)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox7.Text + "','" + avg.ToString("#,0.00") + "','" + tot.ToString("#,0.00") + "')";
SqlCommand cmd = new SqlCommand(ins, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Bindgrid();
}
catch (Exception ex)
{
}
clearcontrols();
}
現在的問題是,當我進入textbox7(價格)大於15的值我的計算是不工作和值不會在數據庫中保存。幫助我解決這個問題。當我進入文本框計算值大於15不工作
我已經在sql.Is中將所有列定義爲十進制數據類型那裏有任何問題嗎?
你應該學習sql注入和如何防止是。由於你的代碼現在是非常脆弱的。第二,如果某人在文本框之一中輸入了不可轉換的值(如字符串),則代碼會拋出錯誤。 – VDWWD