c#中使用动态参数

来源:互联网 发布:网络攻防入门题解 编辑:程序博客网 时间:2024/06/05 15:31
public SqlCommand CreateProcedureCmd(string procName, params SqlParameter[] prams) { if ( conn.State==ConnectionState.Closed)conn.Open();SqlCommand Cmd = new SqlCommand(procName, conn); Cmd.CommandType = CommandType.StoredProcedure; if (prams != null) { foreach (SqlParameter parameter in prams) { if(parameter != null) { Cmd.Parameters.Add(parameter); } } } return Cmd; } 

  此时parmas参数可以按顺序填写参数或者直接添加数组。
原创粉丝点击