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 ; 
}

解决方案 »

  1.   

    个人认为一样,只是处理方式不同,第一种是用输出参数out,相当于传引用,第二个是返回一个int值,貌似这两种效率上的比较实在体现不出来....从习惯上看觉得第二种的思维方式好一点吧
    楼下补充~
      

  2.   

    如果性能出现瓶颈 效率跟不上的话 问题肯定不会出在这样的类似的地方
    多半是数据库操作 或者New一个对象什么的 或者是rount trip太多等
    个人以为通过这个改变性能意义不大(几乎没有) 呵呵