Failed to convert parameter value from a String to a Double C#

I Have a Datalist that is populated by a table and when I try to update the table from the Datalist I get the Exception: "Failed to convert parameter value from a String to a Double"

here is the click of the update button:

for (int x = 0; x < dlQtyBreak.Items.Count; x++)
{
    DataListItem item = dlQtyBreak.Items[x];

    string linenum = ((Label)item.FindControl("lblPBLinenum")).Text;
    string lowqty = ((TextBox)item.FindControl("txtPBLowQty")).Text;
    string highqty = ((TextBox)item.FindControl("txtPBHighQty")).Text;
    string price = ((TextBox)item.FindControl("txtPBPrice")).Text;
    string salesprice = ((TextBox)item.FindControl("txtPBSalesPrice")).Text;
    DAL.Util.updatePriceBreakRow(IQPDID(), lowqty, highqty, price, salesprice, linenum);

}

and this next code is the sql and the parameters

public static void updatePriceBreakRow(string IQPDID, string low, string high, string price, string sPrice, string linenum)
{
    string sql = "UPDATE ItemQtyPriceDiscTable SET  LowQuantity=@LowQty, HighQuantity=@HighQty, Price=@Price WHERE linenum=@lineNum";

    AdoUtil.ACESSQLParameterCollection parameters = new AdoUtil.ACESSQLParameterCollection();
    AdoUtil.ACESSQLParameter param = new AdoUtil.ACESSQLParameter();

    param.ParamName = "@IQPDID";
    param.ParamValue = IQPDID;
    param.ParamDBType = SqlDbType.Int;
    parameters.Add(param);

    param.ParamName = "@LowQty";
    param.ParamValue = low;
    param.ParamDBType = SqlDbType.Float;
    parameters.Add(param);

    param.ParamName = "@HighQty";
    param.ParamValue = high;
    param.ParamDBType = SqlDbType.Float;
    parameters.Add(param);

    param.ParamName = "@Price";
    param.ParamValue = price;
    param.ParamDBType = SqlDbType.Float;
    parameters.Add(param);

    param.ParamName = "@SalePrice";
    param.ParamValue = sPrice;
    param.ParamDBType = SqlDbType.Float;
    parameters.Add(param);

    param.ParamName = "@linenum";
    param.ParamValue = linenum;
    param.ParamDBType = SqlDbType.Int;
    parameters.Add(param);

    param.ParamName = "@update";
    param.ParamValue = lastUpdate;
    param.ParamDBType = SqlDbType.VarChar;
    parameters.Add(param);

    AdoUtil.ExecuteNonQuery(sql, parameters);
}

What can be causing this? When I do the same process on another datalist it works, only difference is that table uses all Int and varchar values where this one uses Float and varchar. If anyone has any helpful insight to help solve this problem it will be greatly appreciated. And if there is any other code that could be useful just ask and I can post it.

Thank you.

Answers


Since you say all your tests have been with out a value populated for "SalesPrice" try removing or commenting out

param.ParamName = "@SalePrice";
param.ParamValue = sPrice;
param.ParamDBType = SqlDbType.Float;
parameters.Add(param);

and then run it as you have been and see if that results in the same or not. It could be holding up on that empty string.

and if it does turn out to be whats causing it just add a check in there and then exclude that parameter


Your other code works because they are using varchar datatpe and string is basically converted to varchar. However, in this situation you need to cast or convert these datatype to double. Because string can't be converted implicitly to double. Here is the solution;

param.ParamName = "@LowQty";
param.ParamValue = Convert.ToDouble(low);
param.ParamDBType = SqlDbType.Float;
parameters.Add(param);

You need to do this for all other double parameters.


Need Your Help

Add data to sql on button click

php html function button qsqlquery

my page receives data which i retrieve with $_post. I display some data and at the bottom of page my button has to save data to mysql. I could submit form to next page, but how do i access the data...

Storm Error when launching multilang subprocess

java c++ apache-storm

I have a storm error when i use the cpp wrapper for storm (StormCpp) who use the ShellBolt's multilang subprocess and this one gives me the next error:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.