Mangesh barmate

Mangesh barmate

  • NA
  • 118
  • 136.2k

How to pass collection values to sql server 2008 Stored Proc

Mar 7 2013 6:43 AM

Hi,

I have a collection and i want to pass that collection values to Stored procedures.

but collection holds multiple rows, how i pass this to stored procedures.

My below C# code is for single row, i want to modfiy it for multiple rows.

Below are my single row code-

public bool PlaSh(Collection<SaleSP> spCollection)

        {                       int recordsAffected = 0;

                string connectionString = "Data Source = ……..";

                using (SqlConnection conn = new SqlConnection(connectionString))

                {

                    conn.Open();


                    SqlParameter[] parms = new SqlParameter[6];

                    parms[0] = newSqlParameter("@RCI", spCollection.ReportingCustomerId.Trim());

                    parms[1] = newSqlParameter("@PID", spCollection.PlanXrefId);

                    parms[2] = newSqlParameter("@PSD", spCollection.EffectiveDate);

                    parms[3] = newSqlParameter("@OC", Convert.ToInt32(spCollection .OptionCode));                                       parms[5] = newSqlParameter("@VA", spCollection.VolumeAmount);

                    recordsAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "usp_ShDetail", parms);

                }

            }


            return recordsAffected > 0 ? true : false;


        }

Here spCollection holds collection rows , i want to process all rows and pass to Stored procedues, how i achieve this!!

thanks.