将类插入Sql数据库 [英] Inserting A Class Into Sql Database

查看:71
本文介绍了将类插入Sql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类名Person,它具有所有字段,如name,age,dob,sex everything....不是我不希望像我们一样将此类数据发送到数据库,但我想将整个课程发送到数据库中,我该如何编写此代码以及如何从数据库中检索该课程...

我需要一些好建议

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

推荐答案

可能有很多方法可以做到:
Solution 1 :
重写类的ToString方法.在ToString方法中,只需追加所有变量的值即可.形成一个字符串并将其放在数据库列中.

Solution 2 :
如果您不想使用它来查看数据或轻松地对其进行修改,则可以对上面的ToString输出进行加密,然后将其保存在数据库中.

Solution 3 :
您可以使用JASON格式.形成字符串并将其保存在数据库中.
变量名称:值
例如姓名:Pravin;年龄:10岁等等....

希望这会有所帮助.
一切顺利.
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.


您可以使用序列化 [ ^ ],这是一种常见的保存所有对象数据
You can use Serialization[^], it is a common way to save all object data


这篇关于将类插入Sql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆