有如下代码,返回查询的首行首列
/// <summary>
/// 返回首行首列
/// </summary>
/// <param name="commandText">未空则返回</param>
/// <returns></returns>
public static object ExecuteScalar(string commandText)
{
DataTable tempDt = Tables.Get(commandText);//Tables.Get(commandText)为根据查询语句返回一个datatable
if (tempDt.Rows.Count > 0)
{
return tempDt.Rows[0][0];
}
else
{
return null;
}
}想问一下,对于tempDt,系统会自然释放占的资源吗 需不需要在返回前新建变量暂存返回值,然后对于tempDt调用dispose()方法后再返回假设commandtext写的不好,tempt数据集非常大,如果不能自然释放资源就很糟糕的。
/// <summary>
/// 返回首行首列
/// </summary>
/// <param name="commandText">未空则返回</param>
/// <returns></returns>
public static object ExecuteScalar(string commandText)
{
DataTable tempDt = Tables.Get(commandText);//Tables.Get(commandText)为根据查询语句返回一个datatable
if (tempDt.Rows.Count > 0)
{
return tempDt.Rows[0][0];
}
else
{
return null;
}
}想问一下,对于tempDt,系统会自然释放占的资源吗 需不需要在返回前新建变量暂存返回值,然后对于tempDt调用dispose()方法后再返回假设commandtext写的不好,tempt数据集非常大,如果不能自然释放资源就很糟糕的。
{}
还是让GC自己去回收吧!