using(){}是什么意思,看下面public int ExecuteSql(string sql){open();if (conn == null) return 0;int iResult = 0;using (SqlCommand sqlcmd = new SqlCommand(sql,conn)){try{sqlcmd.CommandTimeout = 300;sqlcmd.ExecuteNonQuery();iResult = 1;}catch (Ex

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 05:23:45
using(){}是什么意思,看下面publicintExecuteSql(stringsql){open();if(conn==null)return0;intiResult=0;using(Sql

using(){}是什么意思,看下面public int ExecuteSql(string sql){open();if (conn == null) return 0;int iResult = 0;using (SqlCommand sqlcmd = new SqlCommand(sql,conn)){try{sqlcmd.CommandTimeout = 300;sqlcmd.ExecuteNonQuery();iResult = 1;}catch (Ex
using(){}是什么意思,看下面
public int ExecuteSql(string sql)
{
open();
if (conn == null) return 0;
int iResult = 0;
using (SqlCommand sqlcmd = new SqlCommand(sql,conn))
{
try
{
sqlcmd.CommandTimeout = 300;
sqlcmd.ExecuteNonQuery();
iResult = 1;
}
catch (Exception ex)
{
iResult = 0;
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
return iResult;
}

using(){}是什么意思,看下面public int ExecuteSql(string sql){open();if (conn == null) return 0;int iResult = 0;using (SqlCommand sqlcmd = new SqlCommand(sql,conn)){try{sqlcmd.CommandTimeout = 300;sqlcmd.ExecuteNonQuery();iResult = 1;}catch (Ex
在using下面的代码域中,可以使用using后面声明的对象,并且在退出using代码域时,自动执行对象的Dispose方法,具体到这里,就是自动执行sqlcmd.SqlConnection.Close()