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

serialize datatable to a binary file , then add new rows to file

Dear Experts,

Problem :

I need to save a datatable to a binary file , in binary format , in order to make the process fast because the datatable may contain up ten millions rows. So , XML is not favorable because it makes the file large sized , and the process will be slow.
I managed to save the datatable to a binary file , and it works fine , but the problem when I try to add new rows to the existing binary file (using a datatable with the same schema , but different rows data) , it copies the schema of the datatable to the binary file , making it very large.

What is needed:

I need to be able to only add rows to the existing binary file. If you try the below code and run it 3 times , it should create the binary file and then add 5 rows for each save , ie , save 15 rows . But this is not the case. it will save table schema & 5 rows (in binary format) >>> then table schema & 5 rows (in binary format) >>>table schema & 5 rows (in binary format). Table schema itself is very large , and consumes much file size. I need to save the file schema only once , then the 15 rows.
My Code:


Expand|Select|Wrap|Line Numbers
  1. Function GetTable() As DataTable
  2.  
  3.         Dim table As New DataTable     ' Create new DataTable instance.
  4.  
  5.         table.Columns.Add("Dosage", GetType(Integer))  ' Create four typed columns in the DataTable.
  6.         table.Columns.Add("Drug", GetType(String))
  7.         table.Columns.Add("Patient", GetType(String))
  8.         table.Columns.Add("Date", GetType(DateTime))
  9.         ' Add five rows with those columns filled in the DataTable.
  10.         table.Rows.Add(25, "Indocin", "David", DateTime.Now)
  11.         table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
  12.         table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
  13.         table.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
  14.         table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now)
  15.         Return table
  16.     End Function
  17.  
  18.      Private Sub SaveDataTabletoBinary()
  19.         dt = GetTable()
  20.  
  21.         Dim format As New Binary.BinaryFormatter
  22.         Dim ds As New DataSet
  23.         ' ds = DataGridView1.DataSource
  24.  
  25.         Using fs As New FileStream("c:\sar1.txt", FileMode.Append)
  26.             dt.RemotingFormat = SerializationFormat.Binary
  27.  
  28.             'Other option is SerilaizationFormat.XML 
  29.             format.Serialize(fs, ds)
  30.         End Using
  31.     End Sub
  32.  
Thanks
Apr 29 '12 #1
0 1349

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: REM | last post by:
I have some problems. It's dilemma between BLOB, BFILE and takes care of file on file system. What it's advantage?? I import some PDF document in BLOB filed in my database. It's about 1000...
1
by: Daniel Cardoso | last post by:
I don't know what else to try - In my asp.net app, when the file name has Windows-1252 characters (like ã and ç), these characters appear, each one, as two strange characters in the file name label...
19
by: **Developer** | last post by:
When I get the image from the file the file remains locked so the Delete fails with a "used by another process" So I tried using a clone and disposing the obtained image. But that didn't fix...
3
by: KraftDiner | last post by:
Hi! In python I'm able to read in binary data from a file. data = file.read() # Reads in an entire file. However the data is 16bits per sample and python is storing the data in a string. How...
0
by: suryanector | last post by:
anybody knows source code for programs using Index file, inverted file operations, usage of B and B++ trees in C++ language plz send them.
2
abdoelmasry
by: abdoelmasry | last post by:
hi any one can help me plz ?? my code is about opening file as binary then get data from file to edit and rewrite data to file this is the code: #include <cstdlib> #include <iostream>...
10
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
3
by: lalala | last post by:
i need to retrieve the data stored in binary format from file into an array to make comparison.Can some1 write me a sample program ?? ermm something like below... ifstream...
2
by: charlesbritto | last post by:
A C++ program for counting individual string in a text file using file handling functions., for ex: if the text file contains, am a boy,am studying +2,am from chennai Now the result shoud...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.