2007年12月11日 星期二

使用 TableAdapter 時,如何取得 stored procedure 的 return value

Visual Studio 2005的 TableAdapter ,不會回傳 stored procedure 的 return value,解決方法之一是寫一個 partial class ,然後從 CommandCollection 的 Parameters 取得 stored procedure 的 return value ,可以參考:
http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx

namespace ICP.DAL.WebATM_DSTableAdapters{ public partial class WebATM_DSTableAdapter {
public object GetReturnValue(int commandIndex) {
return ((System.Data.SqlClient.SqlParameter)this.CommandCollection[commandIndex].Parameters[0]).Value; }
}
}


範例中的commandIndex,要從 Visual Studio 2005 產生的TableAdapter source code 中的 InitCommandCollection function 找出你要的值。