i have some error in code and i dont understand how to remove it.
double f,g;
string a,b;
con.Open();
cmd = new SqlCommand("select MAX (high) FROM DailyChange WHERE Symbol='" + Currency.SelectedValue.ToString() + "' AND Date='" + Label2.Text + "'", con);
a = cmd.ExecuteScalar().ToString();
f = Convert.ToDouble(a);
Response.Write(f);
con.Close();
con.Open();
cmd = new SqlCommand("select MAX (high) FROM DailyChange WHERE Symbol='" + Currency.SelectedValue.ToString() + "' AND Date='" + Label3.Text + "'", con);
b = cmd.ExecuteScalar().ToString();
g = Convert.ToDouble(b);
Response.Write(g);
con.Close();
It gives me the following error:
Input string was not in a correct format.
Line 81: g = Convert.ToDouble(b);
Loading
Blocked AccountPosted Jul 25, 2011, 6:44 AM
b = cmd.ExecuteScalar().ToString();
I think above command returns null or empty value and you are trying to convert this value to double. Thatswhy that error is coming.
So before converting check the value of "b", it should not null or empty.
or try this
Replace this line
g = Convert.ToDouble(b);
from
double.TryParse(b, out g)
VulpesPosted Jul 25, 2011, 6:54 AM
I'd try (EDITED):
object obj = cmd.ExecuteScalar();
if (!DBNull.Value.Equals(obj))
g = Convert.ToDouble(obj.ToString());
else
g = 0.0; // say
Zoran HorvatPosted Jul 25, 2011, 6:43 AM
Zoran