-1

I am working on ASP.NET web application. In that I have one Edit Information page which has around 40 text-boxes. I need to update the data in the database, so I need to pass the values from all 40 fields into the database.

I am passing 40 parameters to a stored procedure to update data in the database. I need some other way to pass these parameters. Please suggest how to pass multiple parameters to a stored procedure.

Is there any other way to pass data or is it only possible, writing all in parameters list?

Regards, Vivek

3
  • 1
    Can you share your code? Commented Oct 21, 2013 at 15:05
  • what version of SQL Server are you using? Commented Oct 21, 2013 at 15:05
  • 2
    What is the problem with adding 40 parameters? 40 lines of code is really not that bad, if you are feeling particularly lazy you can use the sys.parameters system table to make writing the code quicker: SELECT 'command.Parameters.AddWithValue("' + Name + '", ' + STUFF(Name, 1, 1, '') + 'TextBox.Text);' FROM sys.parameters WHERE Object_ID = OBJECT_ID(N'dbo.YourProcedureName'); Commented Oct 21, 2013 at 15:17

1 Answer 1

1

Forty parameters should not be a showstopper, but if you really want to pass fewer arguments to a stored procedure, you could consider passing an XML argument(s) that encapsulates the 40 values to the stored procedure - for example...

<booksdetail> 
  <isbn_13>800007890</isbn_13> 
  <isbn_10>07890B</isbn_10> 
  <image_url>http://www.whatever.com/Books/large/00/800007890.jpg</image_url> 
  <title>Some Title</title> 
  <description>The incredible story of....</description>
  -- ...
</booksdetail>

...passed to @bookDetail xml instead of the values therein passed to:

@isbn_13 varchar(13),
@isbn_10 varchar(10),
@image_url varchar(100),
@title varchar(100),
@description varchar(250),
-- ...

You would still have to account for the 40 values in the stored procedure, but if your preference is a slimmer stored-proc signature, this approach will achieve as much.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.