473,408 Members | 1,775 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,408 software developers and data experts.

Saving a class instance to a database - HELP !?!

Ste
Hi group,
having done some searching on Google i have managed to save an
instance of my class to a database by first serializing it to a file.

The question i have is: can i do this without having to use a temporary
file ?

Here is the code i'm using:

'Serialize class to filestream
Dim formatter As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter()
Dim stream As New System.IO.FileStream("Input.bin",
System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None)
formatter.Serialize(stream, usrPallets)

'Declare a byte array to save the content of the file to be saved
Dim FileByteArray(stream.Length - 1) As Byte
stream.Read(FileByteArray, 0, stream.Length)

'Add parameter to odbc command
cmdTest.Parameters.Clear()
cmdTest.Parameters.Add(New Microsoft.Data.Odbc.OdbcParameter("Test",
Microsoft.Data.Odbc.OdbcType.Binary, stream.Length,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PALLET", System.Data.DataRowVersion.Current, ""))
cmdTest.Parameters(0).Value = FileByteArray
stream.Close()

'Run SQL insert statement
conTESTSS.Open()
cmdTest.ExecuteNonQuery()
conTESTSS.Close()
TIA,

Ste..
Nov 20 '05 #1
3 1161
"Ste" <st*@ste.com> schrieb
Hi group,
having done some searching on Google i have managed to
save an
instance of my class to a database by first serializing it to a
file.

The question i have is: can i do this without having to use a
temporary file ?


Use a System.IO.MemoryStream instead of a Filestream (without having
evaluated the process itself).
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "Ste" <st*@ste.com> scripsit:
having done some searching on Google i have managed to save an
instance of my class to a database by first serializing it to a file.

The question i have is: can i do this without having to use a temporary
file ?


Serialize it to a 'MemoryStream' (part of 'System.IO').

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Ste
DOH! Thanks guys !!!

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:br************@ID-208219.news.uni-berlin.de...
* "Ste" <st*@ste.com> scripsit:
having done some searching on Google i have managed to save an
instance of my class to a database by first serializing it to a file.

The question i have is: can i do this without having to use a temporary file ?


Serialize it to a 'MemoryStream' (part of 'System.IO').

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

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

Similar topics

4
by: Jacob H | last post by:
Hello list... I'm developing an adventure game in Python (which of course is lots of fun). One of the features is the ability to save games and restore the saves later. I'm using the pickle...
4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
1
by: MIchael McDowell | last post by:
Anyidea how this might be done using and XML Web Service and the XMLSerialzation class? A pointer to an online example would be deeply appreciated. Thankyou in advance, Michael McD
5
by: pcPirate | last post by:
Okay, I've have a mdiparentform and only one mdichild form. My parent form has a toolbar with only one button "Open Record". When a user click on the button, a child form would be shown. My...
3
by: Peter Oliphant | last post by:
Trying to save/load a class instance to a file is tough. The reason is because there is no way to preserve its type other than by conventon. For eample, one can save all the states of the members...
5
by: Mark | last post by:
I have a VB 6 program that I have saved an audio file to using DAO and the appendchunk as is shown at http://support.microsoft.com/kb/103257/EN-US/. ; I have it working fine in that app (it saves...
3
by: shuisheng | last post by:
Dear All, Assume I have two classes: material and shape, as follows class Material { double density; // material attribute, may have more vector<Shape*pShape; // shape objects assocaited...
1
by: TheTeapot | last post by:
I'm looking for a PHP database class which allows database connections to mysql, AND (text/XML) files to store information. I'm looking to use the file storage in a small intranet usage of my...
1
by: =?Utf-8?B?TWFya19C?= | last post by:
I have an unpredictable number of RichTestBoxes, stored in a generic list, that are created at runtime. Currently, I am saving these controls to a file by saving each attribute of each box in...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.