Link to home
Start Free TrialLog in
Avatar of scripter78
scripter78

asked on

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

Avatar of plusone3055
plusone3055
Flag of United States of America image

Avatar of scripter78
scripter78

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of scripter78
scripter78

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amandeep Singh Bhullar
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.