另一个 SqlParameterCollection 中已包含 SqlParameter
如标题,附代码如下:
public void AddNews(Content content)
{
SqlParameter[] parameters = new SqlParameter[7];
SqlParameter parameter = new SqlParameter();
parameter = new SqlParameter();
parameter.ParameterName = "@title ";
parameter.Value = content.Title;
parameters[0] = parameter;
parameter = new SqlParameter();
parameter.ParameterName = "@content ";
parameter.Value = content.ParticularCont;
parameters[1] = parameter;
parameter = new SqlParameter();
parameter.ParameterName = "@time ";
parameter.Value = content.PublishTime;
parameters[2] = parameter;
tool.ExecuteStoreProcedure( "AddNews ", parameters);
}
public void ExecuteStoreProcedure(string spName, SqlParameter[] parameters)
{
try
{
SqlCommand cmd = new SqlCommand(spName);
cmd.CommandType = CommandType.StoredProcedure;
if (parameters != null)
for (int i = 0; i < parameters.Length; i++)
{
cmd.Parameters.Add(parameters[i]);
}
cmd.Connection = this.sqlCon;
if (this.sqlCon.State == ConnectionState.Closed) this.sqlCon.Open();