【发布时间】:2011-05-11 16:46:58
【问题描述】:
我正在使用 c# asp.net,只是尝试在提交数据后以只读格式显示数据。它用于培训,我的处理程序说没有参数化,(它不是用于实际部署);当我运行 select 命令时,我在第一行 GetInt32 抛出 specified cast is invalid 异常。值是整数,列设置为整数。我错过了什么?
string epl = "SELECT Entity, Employees, CA, MI, NY, NJ, Primex, EplLim, EplSir, Premium, Wage, Sublim, SubmissionId FROM EPL WHERE SubmissionId =" + x;
using (SqlCommand epcmd = new SqlCommand(epl, EplConn))
{
SqlDataReader epdr = epcmd.ExecuteReader();
epdr.Read();
LblEplShowEntity.Text = epdr.GetInt32(0).ToString();
LblEplShowTotalEmpl.Text = epdr.GetInt32(1).ToString();
LblEplShowCalEmpl.Text = epdr.GetInt32(2).ToString();
LblEplShowMichEmpl.Text = epdr.GetInt32(3).ToString();
LblEplShowNyEmpl.Text = epdr.GetInt32(4).ToString();
LblEplShowNjEmpl.Text = epdr.GetInt32(5).ToString();
LblEplShowPrimEx.Text = epdr.GetInt32(6).ToString();
LblEplShowLim.Text = epdr.GetInt32(7).ToString();
LblEplShowPrem.Text = epdr.GetInt32(8).ToString();
LblEplShowWage.Text = epdr.GetInt32(9).ToString();
LblEplShowInvestCost.Text = epdr.GetInt32(10).ToString();
epdr.Close();
}
【问题讨论】:
-
如果您要采用字符串表示形式(又名
epdr["Entity"].ToString()并在其上调用int.Parse或int.TryParse,它仍然会给出错误吗?第1 列中返回的实际文本是什么? (索引 0)?
标签: c# asp.net sql-server visual-studio