Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Data Type

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-02-27 : 13:04:21
Hello,

If I need to save an .NET 2.0 class in a SQL 2005 table.
What should be the column type?

And the INSERT/DELETE/UPDATE commands are used as it would be for a string or any other data type?

Thanks,
Miguel

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-02-27 : 13:35:08
I thought a class was a programming language construct used to group related instance variables and methods.

How exactly could you store that as data?





CODO ERGO SUM
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-27 : 14:18:52
If you want to persist an object in your database, you should store the data in your object properly, as a series of table rows and columns with correct indexes and datatypes. i.e., if your class is called "Person" and the class has 3 properties, say "FirstName", "LastName" and "BirthDate", you should create a table called "Persons" (or "People") in your database with those 3 columns (with correct datatypes) and store each object in 1 row in that table with each property going into the appropriate column.

If really want to serialize binary data into the database itself, you need to make sure that your class is serializable, and then you can serialize the object and then use the Image datatype in SQL Server to physically store it. Definitely not recommended unless you really, really have a good reason to do this as it pretty much defeats the entire purpose of having a database.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-02-27 : 14:30:54
quote:

If really want to serialize binary data into the database itself, you need to make sure that your class is serializable, and then you can serialize the object and then use the Image datatype in SQL Server to physically store it. Definitely not recommended unless you really, really have a good reason to do this as it pretty much defeats the entire purpose of having a database.



Hi,

That is exactly what I want to do.
Something like it is done with Profile in Asp.Net 2.0.

Basically I want to have a table in my projects where I store objects, either a string, a class, or anything else.

I will just INSERT, DELETE or UPDATE. Nothing else.

Do you know any article about this?

Thanks,
Miguel

Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-02-27 : 14:32:58
This is just to store miscellaneous information on my projects.
They can be of various data types and they are not always used for the same thing ...

Like a resource table for many things.

Any help would be great.

Thanks,
Miguel
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-27 : 16:39:47
Always remember, Google is your friend. A simple google search of "serialize .net object sql server" returned many articles that should be helpful to you:

http://www.15seconds.com/issue/041124.htm
http://www.eggheadcafe.com/articles/20020929.asp
http://msdn.microsoft.com/msdnmag/issues/02/12/CuttingEdge/
http://www.devx.com/dotnet/Article/16032


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -