How to Pass object having values to Sql store procedure using Asp.Net MVC C#

Hi Experts,

I have an object containing lots of public values ( dropDown,checkbox, radioButton, txtBox etc..) that I want to send across to sql store procedure. Could you please provide some sample code to achieve this in ASP.Net MVC using c# ?

I know there is simple way exists where you can pass on different parameters that I want to avoid.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

satmishaAuthor Commented:
Just to add that the object that I have used is of Type 'System.Collections.Generic.List'. Appreciate your early reply.
ste5anSenior DeveloperCommented:
I have an object containing lots of public values [..]
Bad design.

[..] I want to send across to sql store procedure [..]
Why? A relational database is not an object store. So this is not possible.

What is your use-case? Any actual problem?

But, your wording sounds like you may have already some serious architectural problems..
Obadiah ChristopherDeveloper User InterfaceCommented:
Problem unclear

Do you want to pass entire controls to the database or just the values?
Why do you not want to pass different parameters?

Also to point out, that what ste5an is mentioning is absolutely correct. This is bad design.

From what I am understanding, this is the what you are expecting.

SqlCommand sqlcmd = new SqlCommand();

            List<string> param = new List<string>();

            foreach (var item in param)

Open in new window

Note: For this to work, the sequence of the sql parameters and the values in the Generic list should match.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

satmishaAuthor Commented:
Thanks experts and apologies for putting less info. Let me try to put full perspective now.

Yes, Architecture is extremely poor of this as this is migration application.

Lets say you have an 'Employee' Model in MVC application and this Employee Model is consist of many values like

Class Employee

In db you have table called  StorageTable having following columns


So what I am expecting is to push Employee model mentioned above in the StorageTable, so my final table would become like:

ID      Feature      FeatureValue
1      Name      Tom
1      Code      101
1      Region      Ch
1      Country      USA
1      Salary       20,000
Create a method which will store all the necessary property values into a string with defined separators and pass the string to the SP.  

If you decide the string format can be either XML or JSON then you may use XMLSerializer ( or JavaScriptSerializer (

Of course, any serialization will extend the amount of data stored/processed on SQL Server but SQL Server can work with XML directly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
aha, an EAV model. How do you read your entities (Employee)?
Just a note:
The data model containing
seems to be universal for any data but you have to also think about data queries from such model. Such queries is not easy to optimize and if you decide to have each feature value in its own column on the query output then it results in a bunch of LEFT JOINS.

Of course if we are talking about thousands of rows then the speed does not matter but millions of rows is something different.

And that was the reason ste5an is asking "How do you read your entities (Employee)?".

So we may continue in the discussion or close the question.
satmishaAuthor Commented:
Thanks guys.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.