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();
}
}
ASKER
That is still essentially doing the same thing as
command.Parameters.AddWith Value("@va lue1", 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.
command.Parameters.AddWith
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
http://www.codeproject.com/KB/database/sqlinsertinto.aspx