下面是我用于从列nos
中获取计数的那段代码。在SQL Server中使用count()
//get max count of orders on server .2
public int getmaxcountfornos(string caseno,TextBox TextBox3)
{
int count2 = 0;
try
{
String dd_webCofig = ConfigurationManager.ConnectionStrings["counton140"].ConnectionString;
OdbcConnection ddlistconn = new OdbcConnection(dd_webCofig);
ddlistconn.Open();
string cnt_2 = "select count(nos) from training_jud.orders where [email protected] and [email protected]";
OdbcCommand ddlistCmd_2 = new OdbcCommand(cnt_2, ddlistconn);
ddlistCmd_2.Parameters.AddWithValue("b", caseno);
ddlistCmd_2.Parameters.AddWithValue("c", Convert.ToDateTime(TextBox3.Text).ToString("yyyy-MM-dd"));
count2 = (int)ddlistCmd_2.ExecuteScalar();
}
catch (Exception ee)
{
HttpContext.Current.Response.Write(ee.Message);
}
return count2;
}
在这里,我得到异常作为
指定的转换是无效的。
任何人都可以帮我理清这个问题吗?
可能是因为ExecuteScalar'的'结果不是INT。这可能是一个长期的,或一个单位。在这种情况下演员阵容不会奏效。通过一个字符串(不要这样做)解决这个问题。找出执行查询后实际返回的类型。 – 2011-12-21 07:47:25