I'm updating an old program (written in VS2003 and updating in VS2005) and found the following statement:
sql.Parameters.AddWithValue("@acheck", Double.Parse(txtAmtCheck.Text == "" ? "0.0" : txtAmtCheck.Text));
I'm assuming the intention was to substitute a zero if the textbox was blank -- based on the fact that I get the error that it can't enter a null into that field -- but it doesn't
work now. I know I can say, "If tb == ""....", but I was just curious if anyone had seen anything like this before?
Loading
Posted May 13, 2008, 5:23 PM
SqlParameter param = new SqlParameter();
param.ParameterName = "@aCheck";
param.Value = Double.Parse(String.IsNullOrEmpty(txtAmtCheck.Txt) ? "0.0" : txtAmtCheck.Text);
sql.Parameters.Add(param);
Its weird, because the type double is a struct, it doesnt like null values. Just keep breaking it down and checking the variables, maybe a null is being inserted into the parameter through the Double.Parse() method.
Man... the text formatting on this forum is WEIRD...
Anna HawksPosted May 13, 2008, 5:14 PM
Posted May 13, 2008, 5:06 PM
What error is it giving you? Is it saying that your attempting to insert a null value into the parameter? If thats the case, try this:
sql.Parameters.AddWithValue("@acheck", Double.Parse(String.IsNullOrEmpty(txtAmtCheck.Text) ? "0.0" : txtAmtCheck.Text));