http://blog.csdn.net/hawkjin/archive/2007/05/25/1625271.aspx(转)
1.存储过程
CREATE
PROCEDURE
p1
AS
return 1
GO
return 1
GO
2.C#代码
using
System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace Test
{
public partial class _Default:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgse)
{
Databasedb = DatabaseFactory.CreateDatabase();
string sqlCommand = " p1 " ;
DbCommanddbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddParameter(dbCommand, " myReturnValue " ,DbType.Int32,ParameterDirection.ReturnValue, "" ,DataRowVersion.Current, null );
db.ExecuteNonQuery(dbCommand);
Response.Write(db.GetParameterValue(dbCommand, " myReturnValue " ).ToString());
}
}
}
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace Test
{
public partial class _Default:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgse)
{
Databasedb = DatabaseFactory.CreateDatabase();
string sqlCommand = " p1 " ;
DbCommanddbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddParameter(dbCommand, " myReturnValue " ,DbType.Int32,ParameterDirection.ReturnValue, "" ,DataRowVersion.Current, null );
db.ExecuteNonQuery(dbCommand);
Response.Write(db.GetParameterValue(dbCommand, " myReturnValue " ).ToString());
}
}
}