Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Wednesday, March 21, 2012

Saving a custom object in a sql database table.

Hi,
Using VB.net I have created a custom object (hope my terminology is correct here), it's just a class that defines a few string, integer, and hash table variables. After creating an instance of this class and populating it with data I need to be able to store this instance of my object in a sql server data base table. How do I do this? I saw an article that used the image data type to achieve this (code was in java unfortunately) is this the correct approach. Could you please give me some code examples

Thanks

If you give your class the Serializable attribute, you can bsaically save it to, and load it from a stream, (or string). This means it can be easily saved to a file, database, or even copied across the internet without fear of it being blocked. You can also save it as binary too.

Since you are in effect creating an XML data string when you serialize, you can either save it in an SQL Server 2005 xml field, or into a text field in SQL Server 2000

Have a look athttp://msdn2.microsoft.com/en-us/library/et91as27.aspx

Monday, March 12, 2012

Save Class

Hello,

I created a class in my .Net code and I have an SQL 2005 table with a column of type image (I suppose I should use this type)

After I define the class properties I need create a new record and save the class in the database.

Can I do it the same way as I would save, for example, a string in a varchar field?

Thanks,

Miguel

Hi shapper,

Are you trying to put an object into database? There are many ways.

1. You can serialize the object to Xml or binary, and save the serialized result to a string or binary field.

2. You can define a database table. Each column of the table correspond to a field of the class object. You can create some INSERT/UPDATE/DELETE/SELECT command to do all the operations on the records.