I am reviewing an example project using MVVM and Store Procedures for DB access in SQL Server. I wanted to know if there is a maximum number of fields that can be passed to a Store Procedure from C#.
In the example they put 6 fields, but if I have a table with 30 or 40 fields (invoice, reference guide), considering that the vast majority are entered by the user, is there a better way to send them to the table?
This is the example line of code.
dc.AddProduct(p.CategoryName, p.ModelNumber, p.ModelName, p.UnitCost, p.Description, ref newProductId);
The Column limit in an insert is 4096 columns according to this Article.
I think you wouldn't need a "better way" to send them.
EDIT:
Complement with the part that says
Y
EDIT 2:
Maybe Yes, there is a better way, sending an XML representation of your object to the SP and deserializing it to perform the insert.
something like that:
Deserialization:
But in my opinion, the "traditional" way of doing it is better.
I took this info from This Answer on SO in English, personally I can't understand much how it works but maybe it will help you.
Another way you can do it is by serializing the data you want to send to the database through an XML, in this way you would only be receiving a parameter in your Stored Procedure .
For example, having the following XML:
You can read it in your Stored Procedure as follows:
When executing the Stored Procedure you will only have this:
If you don't have a class with the definition of those 30 fields, it is possible to create the XML dynamically.