Hello group,
I have irrational idea but I thing that this solution is good for me.
In my apps I have custom class MyClass with few public, and private
integers, two ArrayList etc.
How serialize this class to dataBase. I need have completly object in one
place.
I know that I want create few tables and use select command but is too
slowly for me (Select for fill ArrayLists is too slow) I want get object use
SqlReader and I can't (user can't) change objects in dataBase.
PawelR 6 12313
Pawel,
Have a look at this page where I assume that you made your class
serializable http://msdn.microsoft.com/library/de...classtopic.asp
You can use the memorystream with that
I hope this helps?
Cor
"PawelR" <p.a.w.e.l.r.> schreef in bericht
news:OP**************@TK2MSFTNGP09.phx.gbl... Hello group, I have irrational idea but I thing that this solution is good for me. In my apps I have custom class MyClass with few public, and private integers, two ArrayList etc. How serialize this class to dataBase. I need have completly object in one place. I know that I want create few tables and use select command but is too slowly for me (Select for fill ArrayLists is too slow) I want get object use SqlReader and I can't (user can't) change objects in dataBase. PawelR
Thanks,
My question is not "How serialize class?" but
"How serialize class and save this in db?"
Pawel
Użytkownik "Cor Ligthert" <no************@planet.nl> napisał w wiadomości
news:Oc**************@TK2MSFTNGP14.phx.gbl... Pawel,
Have a look at this page where I assume that you made your class serializable http://msdn.microsoft.com/library/de...classtopic.asp
You can use the memorystream with that
I hope this helps?
Cor "PawelR" <p.a.w.e.l.r.> schreef in bericht news:OP**************@TK2MSFTNGP09.phx.gbl... Hello group, I have irrational idea but I thing that this solution is good for me. In my apps I have custom class MyClass with few public, and private integers, two ArrayList etc. How serialize this class to dataBase. I need have completly object in one place. I know that I want create few tables and use select command but is too slowly for me (Select for fill ArrayLists is too slow) I want get object use SqlReader and I can't (user can't) change objects in dataBase. PawelR
PawelR wrote: Hello group, I have irrational idea but I thing that this solution is good for me. In my apps I have custom class MyClass with few public, and private integers, two ArrayList etc. How serialize this class to dataBase. I need have completly object in one place. I know that I want create few tables and use select command but is too slowly for me (Select for fill ArrayLists is too slow) I want get object use SqlReader and I can't (user can't) change objects in dataBase.
I suggest you look at NHibernate, which is a framework for mapping
objects to relational databases. For more information see http://nhibernate.sourceforge.net/
Anders Norĺs http://dotnetjunkies.com/weblog/anoras/
Pawel,
I made a sample, I assume that you know how to save a string in a database.
\\\Needs a form with 2 buttons.
\\\and using System.Runtime.Serialization.Formatters.Binary;
public string str;
private void button1_Click(object sender, System.EventArgs e)
{
mySerClass mine = new mySerClass();
mine.name = "pawel";
BinaryFormatter bf = new BinaryFormatter();
System.IO.MemoryStream mem = new System.IO.MemoryStream();
bf.Serialize(mem, mine);
str = Convert.ToBase64String(mem.ToArray());
}
private void button2_Click(object sender, System.EventArgs e)
{
BinaryFormatter bf = new BinaryFormatter();
System.IO.MemoryStream mem =
new System.IO.MemoryStream(Convert.FromBase64String(st r));
mySerClass mine = (mySerClass)bf.Deserialize(mem);
MessageBox.Show(mine.name);
}
}
[Serializable]
public class mySerClass
{
public string name;
}
}
///
I hope this helps?
Cor
Thenks,
To this moment I not be shure how convert my class to binary value (for db),
now I know.
Thanks You very much, now it's simple.
Pawel
Użytkownik "Cor Ligthert" <no************@planet.nl> napisał w wiadomości
news:%2****************@TK2MSFTNGP12.phx.gbl... Pawel,
I made a sample, I assume that you know how to save a string in a database.
\\\Needs a form with 2 buttons. \\\and using System.Runtime.Serialization.Formatters.Binary; public string str; private void button1_Click(object sender, System.EventArgs e) { mySerClass mine = new mySerClass(); mine.name = "pawel"; BinaryFormatter bf = new BinaryFormatter(); System.IO.MemoryStream mem = new System.IO.MemoryStream(); bf.Serialize(mem, mine); str = Convert.ToBase64String(mem.ToArray()); } private void button2_Click(object sender, System.EventArgs e) { BinaryFormatter bf = new BinaryFormatter(); System.IO.MemoryStream mem = new System.IO.MemoryStream(Convert.FromBase64String(st r)); mySerClass mine = (mySerClass)bf.Deserialize(mem); MessageBox.Show(mine.name); } } [Serializable] public class mySerClass { public string name; } } ///
I hope this helps?
Cor
PawelR wrote: Hello group, I have irrational idea but I thing that this solution is good for me. In my apps I have custom class MyClass with few public, and private integers, two ArrayList etc. How serialize this class to dataBase. I need have completly object in one place. I know that I want create few tables and use select command but is too slowly for me (Select for fill ArrayLists is too slow) I want get object use SqlReader and I can't (user can't) change objects in dataBase.
Deserializing can often be slower than reading values from the DB,
don't forget that. Also by storing data in a blob in a db field, you
lose the option to filter on the data. This might come as a future
enhancement of the software you're writing now.
Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Smith |
last post by:
Hi,
I am using a custom Session Handler.
session_set_save_handler is working well.
But i want to read the data direct from the database.
My problem:
php don't uses the standard serialize...
|
by: Ben Amada |
last post by:
I've created a class that I need to store in ViewState. However when I try
to store it in ViewState, I get the following error:
"The type 'solution.pe2' must be marked as Serializable or have a...
|
by: Brad |
last post by:
I would like to serialize an arraylist of objects to xml so I can store the
xml in a database column. How would I code the serializing and
deserializing? Below is a (overly) simple, incomplete...
|
by: John Manion via .NET 247 |
last post by:
Long Post, thanks for your patience...
I have and XML file that looks something like this:
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
<Location>
<X>30</X>
<Y>40</Y>
</Location>...
|
by: Joe |
last post by:
Hello All,
I want to serialize a hashtable to a database table to persist its values
between postbacks. The client requires that I not use ViewState, hence the
database.
The samples in MSDN...
|
by: Rafi B. |
last post by:
I'm running this on a Linux/CentOs/cPanel server, trying to add caching
to my PHP5 code, using ADOdb. I have two Linux servers, one of them is
running perfect, the second one, just crashes without...
|
by: js |
last post by:
Does anybody knows how to solve the problem? I added
attribute to the following classes in
Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get
the error. Thanks.
...
|
by: VooDoo |
last post by:
Hi,
I am using the serialize and unserialize to put and get data from mysql
database.
I think i could optimise the way i handle the data, but not really sure how.
What is the best way to happend...
|
by: Andy B |
last post by:
I have the following code in a default.aspx web form page_load event. There
seems to be a problem with line 5 (NewsArticle.Date = line).
//create a news article
NewsArticle NewsArticle = new...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |