Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I have created a class name Person and it has all the fields like name,age,dob,sex everything.... not i want to send the data of this class to the databse not like we do but i want to send the entire class into the database how can i write this code and how will i retrive this class from the database...

I need some good suggestion
Posted

There could be lots of ways to do this :
Solution 1 :
Override the ToString method of class. In the ToString method just append the values of all the variables. Form a string and put it in database column.

Solution 2 :
If you do not want use to see the data or modify it easily, you can encrypt the above ToString output and then save it in the database.

Solution 3 :
You can use JASON format like. Form the string and save it in the database.
Variable Name : Value
e.g. Name : Pravin; Age : 10 etc.....

Hope this helps.
All the best.
 
Share this answer
 
Comments
Kishore Jangid 19-Sep-11 2:14am    
So when a user fills a forma and then when he clicks the submit or insert button how should i bind those data to the class and and how to modify the inserted data..........
You can use Serialization[^], it is a common way to save all object data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900