问题描述
我有一个sql表格如下:
创建表格CrossElasticity
(
CrossElasticity float,
)
通过存储过程将值保存为:
创建proc Usp_saveCrossElasticity(@CrossElasticityValue float)
as
begin
update CrossElasticity set CrossElasticityValue = @ CrossElasticityValue
结束
创建proc usp_GetCrossElasticity
as
开始
从CrossElasticity中选择CrossElasticityValue
end
现在,我试图将价值保存为0.512但是它保存为0.51200001023
但我只想要0.512。怎么做。?
(使用sql server 2012 adv和visual studio 2013)
我的尝试:
访问:
protected void btnCrossElasticitySave_Click(object sender,EventArgs e)
{
if(txtCrossElasticityValueNew.Text ==)
{MessageBox.Show(Please fill proper Values ..); }
其他
{
试试
{
con.Close() ;
con.Open();
SqlCommand cmd1 = new SqlCommand(Usp_saveCrossElasticityValue,con);
cmd1.CommandType = CommandType。 StoredProcedure;
cmd1.Parameters.Add(new SqlParameter(@ CrossElasticityValue,SqlDbType.Float));
cmd1.Parameters [ @CrossElasticityValue]。Value = Convert.ToSingle(txtCrossElasticityValueNew.Text);
int RowCount = cmd1.ExecuteNonQuery();
if(RowCount> 0)
{
MessageBox.Show(保存成功。 。!!;
}
其他
{
MessageBox.Show(有些东西错了。 。!);
}
}
catch(例外情况)
{
MessageBox.Show(ex.ToString());
}
}
}
i have a sql table as:
create table CrossElasticity
(
CrossElasticity float,
)
saving values to it by stored procedure as:
create proc Usp_saveCrossElasticity(@CrossElasticityValue float)
as
begin
update CrossElasticity set CrossElasticityValue=@CrossElasticityValue
end
create proc Usp_GetCrossElasticity
as
begin
select CrossElasticityValue from CrossElasticity
end
now, i am trying to save value as 0.512 but it save as 0.51200001023
but i just want 0.512 exactly.! how to do that.?
(using sql server 2012 adv and visual studio 2013)
What I have tried:
accessed as :
protected void btnCrossElasticitySave_Click(object sender, EventArgs e)
{
if (txtCrossElasticityValueNew.Text == "")
{ MessageBox.Show("Please fill Proper Values.."); }
else
{
try
{
con.Close();
con.Open();
SqlCommand cmd1 = new SqlCommand("Usp_saveCrossElasticityValue", con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("@CrossElasticityValue", SqlDbType.Float));
cmd1.Parameters["@CrossElasticityValue"].Value = Convert.ToSingle(txtCrossElasticityValueNew.Text);
int RowCount = cmd1.ExecuteNonQuery();
if (RowCount > 0)
{
MessageBox.Show("Saved Successfully..!!");
}
else
{
MessageBox.Show("Something Went Wrong..!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
推荐答案
这篇关于如何在SQL数据库中存储确切的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!