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 AccountRank #403 · 6.2K reputationPosted Jul 25, 2011, 2:44 AM EDT
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)
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 25, 2011, 2:43 AM EDT
Zoran
VulpesRank #55 · 29.2K reputationPosted Jul 25, 2011, 2:54 AM EDT
I'd try (EDITED):
object obj = cmd.ExecuteScalar();
if (!DBNull.Value.Equals(obj))
g = Convert.ToDouble(obj.ToString());
else
g = 0.0; // say