以下是C#代碼:
/// <summary> /// 執行存儲過程,返回" 返回值" /// </summary> /// <param name="storedProcName">存儲過程名</param> /// <param name="parameters">存儲過程參數</param> /// <returns>執行存儲過程的返回值</returns> public static int RunProcedureWithReturn(string storedProcName, IDataParameter[] parameters) { using (SqlConnection connection = new SqlConnection(connectionString)) { int result; connection.Open(); SqlCommand command = BuildIntCommand(connection, storedProcName, parameters); command.ExecuteNonQuery(); result = (int)command.Parameters["ReturnValue"].Value; //Connection.Close(); return result; } } /// <summary> /// 創建 SqlCommand 對象實例(用來返回一個整數值) /// </summary> /// <param name="storedProcName">存儲過程名</param> /// <param name="parameters">存儲過程參數</param> /// <returns>SqlCommand 對象實例</returns> private static SqlCommand BuildIntCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters) { SqlCommand command = BuildQueryCommand(connection, storedProcName, parameters); command.Parameters.Add(new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null)); return command; }
詳細請下載源代碼
http://files.cnblogs.com/files/sosoft/hovertreeCode.rar
使用VS2015+SQL 2008
參考:http://hovertree.com/hvtart/bjae/ie4k7lxq.htm
謎語:塵封之後了一生(10筆字)
http://m.hovertree.com/miyu/bjae/8kheebew.htm
更多文章:http://www.cnblogs.com/sosoft/p/kaifajishu.html