473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Storing objects in SQL Server table

Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.
Nov 16 '05 #1
10 3046
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
as a special constructor which takes a SerializationInfo and something else
(for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like
'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the opposite as well?

Regards,

Diego F.

Nov 16 '05 #2
But if I store the objects directly as binary data, can I make querys in the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell as a special constructor which takes a SerializationInfo and something else (for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like
'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each

attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.


Nov 16 '05 #3
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in the table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
as a special constructor which takes a SerializationInfo and something

else
(for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like 'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table.

Which is the easiest way to do it? Do I need to write methods to store each

attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.



Nov 16 '05 #4
But is it difficult to write a method that just maps the object attributes
into a table fields?

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and overrride the method that it forces you to override (for serializing)

aswell
as a special constructor which takes a SerializationInfo and something

else
(for deserializing). These two methods are where you choose what data you want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like 'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> the easiest way to do it? Do I need to write methods to store each
attribute
> separately from C# app to the table and the opposite as well?
>
> Regards,
>
> Diego F.
>
>



Nov 16 '05 #5
Diego F. wrote:
But is it difficult to write a method that just maps the object attributes
into a table fields?
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
> Haven't had cause to do it myself but you derive from ISerializable, and > overrride the method that it forces you to override (for serializing)
aswell
> as a special constructor which takes a SerializationInfo and something
else
> (for deserializing). These two methods are where you choose what data

you
> want to serialize, by adding and retrieving name-value pairs.
> In the Serialization namespace, there's then a class called something

like
> 'BinaryFormatter' which takes an array of the serializable objects and
> converts them to a binary stream.
> Look on msdn under 'ISerializable'.
>
>
> "Diego F." <di*****@NOterra.es> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> > the easiest way to do it? Do I need to write methods to store each
> attribute
> > separately from C# app to the table and the opposite as well?
> >
> > Regards,
> >
> > Diego F.
> >
> >
>
>



Nov 16 '05 #6
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.


Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a
collection.

Maybe I have to use a thirds tool. I have seen one from Mongoose Solutions
(Objectz.NET)

Regards,

Diego F.
Nov 16 '05 #7
Diego F. wrote:
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.


Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a
collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in the
db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects and
the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #8
What I have is that:

- A first object that has simple types: int, float and string. Call it
Customer.
- A second object that is a collection of Customer objects: that is:

public class Customers: CollectionBase
{
public Customer this [int index]
{
get { return (Customer)this.List[index]; }
}
public void Add(Customer c)
{
this.List.Add(c);
}
}

- A third object that includes int, string, float and Customers.

I work with the third type objects and in a point of the application, I have
a Hashtable with these objects. What I need is storing them in the database
and later make some queries. I don't need to convert to objects again.

Can you help me?

Regards,

Diego F.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> escribió en el
mensaje news:xn***************@msnews.microsoft.com...
Diego F. wrote:
Let me say that it took me more than a year and 3.5 MB of C# code :). The technique you're looking for is 'O/R mapping'.

Frans.

Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in

the db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects and the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Nov 16 '05 #9
Diego F. wrote:
What I have is that:

- A first object that has simple types: int, float and string. Call it
Customer.
- A second object that is a collection of Customer objects: that is:

public class Customers: CollectionBase
{
public Customer this [int index]
{
get { return (Customer)this.List[index]; }
}
public void Add(Customer c)
{
this.List.Add(c);
}
}

- A third object that includes int, string, float and Customers.

I work with the third type objects and in a point of the application, I have
a Hashtable with these objects. What I need is storing them in the database
and later make some queries. I don't need to convert to objects again.
You mean:
Customer (first)
which has a collection Orders (second)
forming
the third object?

if so, of course this is handled.

Frans

Can you help me?

Regards,

Diego F.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> escribió en el
mensaje news:xn***************@msnews.microsoft.com...
Diego F. wrote:

> Let me say that it took me more than a year and 3.5 MB of C# code :). The > technique you're looking for is 'O/R mapping'.
>
> Frans.
>

Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in

the
db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects

and
the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP


--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #10
Well, it would depend largely on what the object's attributes are!

You're not going to get something packaged and out-of-the-box, it would sound like you'll have to write an algorithm to do what you want.

Remember the meaning of "I.T." - Information Technology. Go forth and apply some of the Technology that you understand to the Information you've got.
"Diego F." wrote:
But is it difficult to write a method that just maps the object attributes
into a table fields?

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
> Haven't had cause to do it myself but you derive from ISerializable, and > overrride the method that it forces you to override (for serializing)
aswell
> as a special constructor which takes a SerializationInfo and something
else
> (for deserializing). These two methods are where you choose what data

you
> want to serialize, by adding and retrieving name-value pairs.
> In the Serialization namespace, there's then a class called something

like
> 'BinaryFormatter' which takes an array of the serializable objects and
> converts them to a binary stream.
> Look on msdn under 'ISerializable'.
>
>
> "Diego F." <di*****@NOterra.es> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> > the easiest way to do it? Do I need to write methods to store each
> attribute
> > separately from C# app to the table and the opposite as well?
> >
> > Regards,
> >
> > Diego F.
> >
> >
>
>



Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
I have a system that basically stores a database within a database (I'm sure lots have you have done this before in some form or another). At the end of the day, I'm storing the actual data...
6
by: Kieran Benton | last post by:
Hi, I have quite a lot of metadata in a WinForms app that I'm currently storing within a hashtable, which is fine as long as I know the unique ID of the track (Im storing info on media files). Up...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.