本文介绍了字符串格式正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中有一些错误,我不知道如何删除它.

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();


它给了我以下错误:
输入的字符串格式不正确.
第81行:g = Convert.ToDouble(b);


It gives me the following error:
Input string was not in a correct format.
Line 81: g = Convert.ToDouble(b);

推荐答案

object b = cmd.ExecuteScalar();

double result;

if((b != null) && double.TryParse(b.ToString(), out result){

// Do something with result

}
else{
// Result is either null or not a double value. Proceed accordingly
}



try
{

g = Convert.ToDouble(b);
}
catch(Exception)
{
}


编写剩余的代码.
问候,
shefeek


write the remaining code.
regards,
shefeek


这篇关于字符串格式正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 10:58