我试图转换这段代码:
try
{
recordID = Int64.Parse(SqlHelper.ExecuteScalar(conn, CommandType.Text, sqlString, parms).ToString());
}
catch (Exception ex)
{
int x = 1;
}转换成TryParse代码。我需要渔获物(例外)吗?
发布于 2016-02-19 16:48:38
TryParse方法本身不需要catch子句。但是您的代码中还有很多其他调用。如果DB中有int列类型,我建议直接使用该值:
try
{
recordID = Convert.ToInt64(SqlHelper.ExecuteScalar(conn, CommandType.Text, sqlString, parms));
}
catch (Exception ex)
{
LogError(ex);
}因为转换到字符串然后从字符串转换是额外的工作。
https://stackoverflow.com/questions/35503570
复制相似问题