我正在尝试从 .net 执行 SQL Server 存储过程。我收到错误
将数据类型数字转换为十进制时出错
但我很难确定哪个 SQL 参数是罪魁祸首。
有 70 个,所以我确信有比手动搜索更简单的方法。
它是否在异常框中的某个地方,在“查看详细信息”中?提前致谢..
相关代码(希望这会有所帮助......我没有包含所有参数,但这是模式):
public void WriteKeyStatToDB(KeyStatisticsDataCollection.KeyStatsDP dp)
{
SqlParameter symbol = SqlParameterFactory("@symbol", SqlParamInOrOut.Input, SqlDbType.Char);
SqlParameter dateAdded = SqlParameterFactory("@dateAdded", SqlParamInOrOut.Input, SqlDbType.Date);
SqlParameter tradeDate = SqlParameterFactory("@tradeDate", SqlParamInOrOut.Input, SqlDbType.Date);
SqlParameter marketCapIntra = SqlParameterFactory("@marketCapIntra", SqlParamInOrOut.Input, SqlDbType.Money);
SqlParameter entVal = SqlParameterFactory("@entVal", SqlParamInOrOut.Input, SqlDbType.Money);
SqlParameter trailingPE = SqlParameterFactory("@trailingPE", SqlParamInOrOut.Input, SqlDbType.Decimal);
SqlParameter forwardPE = SqlParameterFactory("@forwardPE", SqlParamInOrOut.Input, SqlDbType.Decimal);
symbol.Value = dp.Symbol;
dateAdded.Value = dp.TradeDate;
tradeDate.Value = dp.TradeDate;
marketCapIntra.Value = dp.MarketCapIntraDay;
entVal.Value = dp.EntValue;
trailingPE.Value = dp.TrailingPE;
forwardPE.Value = dp.ForwardPE;
List<SqlParameter> sqlParams = new List<SqlParameter> {symbol, dateAdded, tradeDate, marketCapIntra, entVal, trailingPE, forwardPE};
ExecuteSproc("spAddKeyStatDP", sqlParams, SqlConnection);
}
private static SqlParameter SqlParameterFactory (String ParamName, SqlParamInOrOut Direction,
SqlDbType SqlType)
{
SqlParameter param = new SqlParameter
{
ParameterName = ParamName,
SqlDbType = SqlType
};
if (Direction == SqlParamInOrOut.Input)
param.Direction = ParameterDirection.Input;
else
param.Direction = ParameterDirection.Output;
return param;
}
private static void ExecuteSproc(String CommandName, List<SqlParameter> ParamList, SqlConnection SqlConn, int Timeout = 0)
{
using (SqlCommand cmd = new SqlCommand(CommandName, SqlConn))
{
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter sp in ParamList)
{
if (sp.Value == null)
sp.Value = DBNull.Value;
cmd.Parameters.Add(sp);
}
cmd.CommandTimeout = Timeout;
cmd.ExecuteNonQuery();
}
}
}