We help IT Professionals succeed at work.

How to insert Class values into a set of SQL Command Parameters

Ok below is an example of what I am trying to accomplish. People are able to create an account and all of the info is stored into a class object which than is inserted into the database via the below code but as you can see I am missing how to do this with the least amount of lines of code as possible. I could go a real long way about this and write out everything but trying to make this very small code.

        public void CreatAccount(List<Profile> profile)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionStrings.Connection))
            {
                SqlCommand command = connection.CreateCommand();

                command.CommandText = "CreateNewProfile";
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(profile);
                
                
                connection.Open();

            }
        }

Open in new window

Comment
Watch Question

Author

Commented:
That is still essentially doing the same thing as

command.Parameters.AddWithValue("@value1", profile.City);

which means I would have to add a value for each parameter by hand. I have 46 Parameters to enter. Although I am sure that by time I find a solution to doing it in the fewest lines of code possible I could have done it the long way but the point is being able to do it in the fewest lines possible.
I have found something close to what I am looking for here
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy(v=VS.85).aspx

sqlbulkcopy
but not 100% that is the most effective way to go
BRONZE EXPERT

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.