无法将参数值从字符串转换为十进制. [英] failed to convert parameter value from string to decimal..?

查看:133
本文介绍了无法将参数值从字符串转换为十进制.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将记录添加到sql表时遇到错误
我的tblCash包含cCash column.decimal(18,4)

protected void btnAdd_Click(object sender, EventArgs e)
    {
        
        txtAmount.Text = "";
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_Insert_Update_Record";
       
        SqlParameter cash=new SqlParameter("@Cash",SqlDbType.Decimal);
        cash.Value = txtAmount.Text;
        cmd.Parameters.Add(cash);
        


       
     
       cmd.ExecuteNonQuery();
     
       lblMessage.Text = "Amount Added";
       txtAmount.Text = "";
       lblMessage.Text = "";
       con.Close();
       cmd.Dispose();

    }


这是我的sp

alter proc usp_Insert_Update_Record
@status int,
@money decimal (18,4)
as
if(@status=1)
begin
update tblCash set cCash=cCash+@money
end
else if (@status=2)
begin
declare @balanceAmount decimal(18,4)
select @balanceAmount=cCash from tblCash
if(@money>@balanceAmount)
begin
Print ''You can not update amount as Balance amount is less than input Amount''
end
else
begin
update tblCash set cCash=cCash-@money
end
end


出现错误,例如无法将参数值从字符串转换为十进制
有人可以建议我如何解决吗?

可以给我打电话给我如何为状态分配值..但是我要添加我的表状态..有人可以建议我吗?

@ d4742我也分配了值,但是如果我将其分配为convert.todouble(txtAmount.text);它即将出现的错误(例如输入字符串)的格式不正确.
有人可以帮忙吗?

@Sagar Wasule..i在我的表中将十进制(18,4)用于cCash
请任何人帮帮我..

解决方案

第一个错误:您在sp中使用@status,但没有为该变量分配任何值


第二次错误

SqlParameter cash = new SqlParameter("@ Cash",SqlDbType.Decimal);
cash.Value = txtAmount.Text;

现金在哪里???


检查表中用于现金列的数据类型,可能是varchar或字符串引起了某些问题 blockquote>

hi am getting error while adding records to sql table
my tblCash contains cCash column.decimal(18,4)

protected void btnAdd_Click(object sender, EventArgs e)
    {
        
        txtAmount.Text = "";
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dbConnection"].ToString());

        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_Insert_Update_Record";
       
        SqlParameter cash=new SqlParameter("@Cash",SqlDbType.Decimal);
        cash.Value = txtAmount.Text;
        cmd.Parameters.Add(cash);
        


       
     
       cmd.ExecuteNonQuery();
     
       lblMessage.Text = "Amount Added";
       txtAmount.Text = "";
       lblMessage.Text = "";
       con.Close();
       cmd.Dispose();

    }


and here is my sp

alter proc usp_Insert_Update_Record
@status int,
@money decimal (18,4)
as
if(@status=1)
begin
update tblCash set cCash=cCash+@money
end
else if (@status=2)
begin
declare @balanceAmount decimal(18,4)
select @balanceAmount=cCash from tblCash
if(@money>@balanceAmount)
begin
Print ''You can not update amount as Balance amount is less than input Amount''
end
else
begin
update tblCash set cCash=cCash-@money
end
end


am getting error like failed to convert parameter value from string to decimal
can any one suggest me how to solve.?

and can any one tel me how to assign value for status..but i din add in my table status..can any one suggest me?

@d4742 i assigned value also but if i assign as convert.todouble(txtAmount.text);its coming error like input string was not in a correct format.
can anybody help?

@Sagar Wasule..i used decimal(18,4) for cCash in my table
please any one help me..

解决方案

first error : u r using @status in your sp but u r not assigning any value to that varible


second error

SqlParameter cash=new SqlParameter("@Cash",SqlDbType.Decimal);
cash.Value = txtAmount.Text;

where is cash????

use Conver.ToDouble(txtAmount.Text) while assigning value.


Check for the data type used in table for cash column , might be it is varchar or string that is causing some problem


这篇关于无法将参数值从字符串转换为十进制.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆