2个方法那个好. 好在那里.为什么好. protected void RunCommand(string commandString,out int rowsAffected)
{
if(this.Connection==null)
this.Connection=new SqlConnection(this.connectionString);
if(this.Connection.State!=System.Data.ConnectionState.Open)
Connection.Open();
SqlCommand command = BuildCommand( commandString );
rowsAffected = command.ExecuteNonQuery();
Connection.Close();
this.Connection.Dispose();
}protected int RunCommand(string commandString)
{
int rowsAffected;
if(this.Connection==null)
this.Connection=new SqlConnection(this.connectionString);
if(this.Connection.State!=System.Data.ConnectionState.Open)
Connection.Open();
SqlCommand command = BuildCommand( commandString );
rowsAffected = command.ExecuteNonQuery();
Connection.Close();
this.Connection.Dispose();
return rowsAffected ;
}
{
if(this.Connection==null)
this.Connection=new SqlConnection(this.connectionString);
if(this.Connection.State!=System.Data.ConnectionState.Open)
Connection.Open();
SqlCommand command = BuildCommand( commandString );
rowsAffected = command.ExecuteNonQuery();
Connection.Close();
this.Connection.Dispose();
}protected int RunCommand(string commandString)
{
int rowsAffected;
if(this.Connection==null)
this.Connection=new SqlConnection(this.connectionString);
if(this.Connection.State!=System.Data.ConnectionState.Open)
Connection.Open();
SqlCommand command = BuildCommand( commandString );
rowsAffected = command.ExecuteNonQuery();
Connection.Close();
this.Connection.Dispose();
return rowsAffected ;
}
楼下补充~
多半是数据库操作 或者New一个对象什么的 或者是rount trip太多等
个人以为通过这个改变性能意义不大(几乎没有) 呵呵