1

Is there a better way to pass more than 35 paramteres to a SQL Server stored procedure?

I have a web page consisting of more than 35 input controls (textboxes, dropdown lists, date pickers), and I need to pass all those to the stored procedure to insert those values into a table.

I am using current basic approach as shown below:

cmd.Parameters.Add("@SplProjectNum1", SqlDbType.VarChar).Value = txtPromptNumber;
cmd.Parameters.Add("@SplProjectNum2", SqlDbType.VarChar).Value = ProjectClosureDate.ToString();
cmd.Parameters.Add("@SplProjectNum3", SqlDbType.VarChar).Value =  txtPromptNumber;            
cmd.Parameters.Add("@SplProjectNum4", SqlDbType.VarChar).Value = txtPromptNumber;
cmd.Parameters.Add("@SplProjectNum5", SqlDbType.VarChar).Value = txtPromptNumber;
cmd.Parameters.Add("@SplProjectNum6", SqlDbType.VarChar).Value = txtPromptNumber;
...
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Akshay
  • 1,412
  • 2
  • 17
  • 51

1 Answers1

1

Create a class with all the parameters are the properties in it, then create a object and assign the values to the properties. After that you can serialize the object to XML, and pass this XML to your stored procedure. In this method later you can add additional properties in your class, that will automatically add in the XML data you passed to the stored procedure, so there is no change in the parameter or signature of the stored procedure. Inside the stored procedure you can parse the XML data and fetch the required values.

Your stored procedure have only one parameter all time,

CREATE PROCEDURE SPABC_XYX ( @P_XML XML) ...
Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48