如何将带参数的存储过程传递给函数。
我实际上有一个将数据插入数据库的函数。我正在寻找一种方法,可以将带有参数的 SP 传递给该插入函数,以便重用插入数据代码。
将对存储过程的调用放在一个方法中,并从您想要调用它的任何地方调用此方法。将参数(字符串、整数、双精度......)传递给此方法,并将这些值放入存储过程的参数中。
这样您就可以将所有 SP 代码保存在一个地方。
public class CustomerProvider
{
    public int UpdateCustomer(int id, string name, string address)
    {
        using(connection = new
            SqlConnection("Server=localhost;DataBase=Northwind;Integrated Security=SSPI"))
        {
            connection.Open();
            var command = new SQLCommand("csp_updatecustomer", connection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(
            new SqlParameter("@CustomerID", id));
            command.Parameters.Add(
                new SqlParameter("@CustomerName", name));
            command.Parameters.Add(
                new SqlParameter("@CustomerAddress", address));
            var result = command.ExecuteNonQuery();
            return result;
        }
    }
}