示例
存储过程是:
CREATE Procedure CustomerAdd
(
    @FullName   nvarchar(50),
    @Email      nvarchar(50),
    @Password   nvarchar(50),
)
ASINSERT INTO Customers
(
    FullName,
    EMailAddress,
    Password
)VALUES
(
    @FullName,
    @Email,
    @Password
)RETURN @@IdentityGO
C#代码为:
using System;
using System.Data;
using System.Data.SqlClient;public class AddCustomer
{
    public static void Main() 
    {
        string connectionString = "Data Source=localhost;" +
                       "Initial Catalog=store;Integrated Security=SSPI";
        string procedure = "CustomerAdd";        // Create ADO.NET objects.
        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand(procedure, con);        // Configure the command.
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter param;        // Add the parameter representing the return value.
        param = cmd.Parameters.Add("@CustomerID", SqlDbType.Int);
        param.Direction = ParameterDirection.ReturnValue;        // Add the input parameters.
        param = cmd.Parameters.Add("@FullName", SqlDbType.NVarChar, 50);
        param.Value = "John Smith";        param = cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50);
        param.Value = "[email protected]";        param = cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 50);
        param.Value = "opensesame";        // Execute the command.
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();        param = cmd.Parameters["@CustomerID"];
        Console.WriteLine("New customer has ID of " + param.Value);    }
}