Need Expert Help and Advice. Thank You.

S

shapper

Hello,

Consider I have a String:

Dim MyString As String = "Hello"

or an Integer:

Dim MyInteger As Integer = 100

or a class which its properties:

Dim MyClass As New MyCustomClass
MyClass.Property1 = "Hello"
MyClass.Property2 = Unit.Pixel(100)
MyClass.Property3 = 100

Or even a control:

Dim MyLabel As Label
MyLabel.Id = "MyLabel"
MyLabel.CssClass = "MyLabelCssClass"

Is there a way to save a String, an Integer, a Boolean, a Class, a
Control in an SQL database?

Something like:

Define something (Integer, String, Class, Control, etc)

Save in SQL 2005 Database

Later in code Retrive from database given its ID

Is this possible?

How should I do this?

What type of SQL 2005 table field should be used to store the
information?

I have been also using Enterprise Library Data Access Block.
Not sure if I can do this using it.

Thanks,

Miguel
 
L

lord.zoltar

Hello,

Consider I have a String:

Dim MyString As String = "Hello"

or an Integer:

Dim MyInteger As Integer = 100

or a class which its properties:

Dim MyClass As New MyCustomClass
MyClass.Property1 = "Hello"
MyClass.Property2 = Unit.Pixel(100)
MyClass.Property3 = 100

Or even a control:

Dim MyLabel As Label
MyLabel.Id = "MyLabel"
MyLabel.CssClass = "MyLabelCssClass"

Is there a way to save a String, an Integer, a Boolean, a Class, a
Control in an SQL database?

Something like:

Define something (Integer, String, Class, Control, etc)

Save in SQL 2005 Database

Later in code Retrive from database given its ID

Is this possible?

How should I do this?

What type of SQL 2005 table field should be used to store the
information?

I have been also using Enterprise Library Data Access Block.
Not sure if I can do this using it.

Thanks,

Miguel

You can save strings and integers to a database as they are. just save
them into a table with a corresponding string or integer field.
Classes (and Controls, but controls are also classes) are a bit
trickier, but also possible. You have to mark the class with the
<serializable()> attribute. You will also have to implement a special
constructor for deserializing the object (for when you retreive it
from the database) - check in the documentation, I forget exactly
what its signature looks like. You also have to implement a method to
serialize the class.
Once you can do a binary serialization of the class in question, you
have to be able to write it into a binary stream that your database
can understand. Most database systems have a binary object type.
reading and writing the data from the databsae CORRECTLY can be
tricky, and the database you are using may determine exactly how you
do this.
The topic you should research a little more: serialization! It's not
hard, but there is a lot to cover, more than I can cover in this post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top