Serialize Datatable To A Binary File Then Add New Rows To File
Apr 29, 2012
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.
I'm just new to the forums, so I hope you's don't mind me jumping in and asking a question Currently I am pulling out rows from my Datagridview and sending all rows to a .csv file. I now need to retrieve information from two different datatables and put them into the same .csv file I am using. Below is how I am currently retrieving the first part of my .csv file. The second part will below the rows supplied from the datagrid. Hope somebody could advise me on how i could go about or, or have support links.
i need to read binary file and in this file found the string and replace it with other one and save the file afterwords. I found many example to read binary, but to find and replace is for me mistery.
I need to write data to a file, preferably in binary format, but I am unaccustomed with the concept. Where's the easiest place to get the basics? I could come here with a specific need, but I'm at the point right now where I am more willing to work within the confines of keeping it simple.
Here's what I know: 1. how to open a new file 2. how to specify the record length 3. how to close the file
Some specific questions:
Does the record length have to be constant throughout the file?
Can I read the nth record without reading the whole file?
I have a csv file. I need to open it, delete whole row on basis of a column value, Update few of the column values and save the file as .dat file. I am using VB.net 2010
I am trying to serialize object in method binary mode. However, I would like to get a file in human-unreadable format. which means i want to encrypt file. In my memory, if i want to write text into binary file in C, when I set writing mode as binary, I will get a file in human-unreadable format, but in .net, I can't get that.
I've gone through about 16 hours and two packs of cigarettes trying to figure this out. First a little background. I was using 6.0 up until 2004 when I went to prison. I'm out now, and trying to relearn the trade, using VS 2005. I'm currently porting some 6.0 code from another project, SpyCast Webcam Studio, into VB 8.0. It's disheartening, to say the least. None of the old built-in subs/functions work anymore, so I have to scour the forums to relearn each and every function.The section I'm doing now takes a snapshot from the webcam (Video API --> PictureBox --> Save as Jpeg), then upens the file to upload it to the server via HTTP POST. I've been using this code in SpyCast for years with no trouble, but I spent many hours trying to piece together the right code to open the binary file to read its contents. I pieced together two methods I found around the forums, one using FileStream() though the code I found wasn't for binary files, even though it said it was, so that code doesn't really work. Method two uses Microsoft.VisualBasic.FileOpen() and works better.
Here's the kicker. By the time I run through the rest of the rigamarole of uploading the file, by the time I read it on the webserver, it's *slightly* corrupted. It's a valid Jpeg, no errors, but the picture looks like when I use to watch the Playboy Channel when I was a kid scrambled with weird colors and whatnot. [code] Each "chunk" is basically one "line" of the file. It looks like a single LineInput() return is the text between two carriage returns. Am I correct? I tested this with a flat text file, and it looks true. However, That one input line returns the text or data with the carriage returns *stripped*! ***?!? =( Fine, I have no problem adding my own vbCrLf to each LineInput(), if I were opening text. but this's binary. A character could be Chr(10) or Chr(13), both of which are removed from the original file contents.So I could very well need to use something other than LineInput(), but I haven't found any other examples on the web using this method.
however, I am stuck at BinaryReader.actually this is what i am trying to acheive through VB.NET.say for the following file type :
JPG file = FF D8 FF E0 BMP file = 42 4D BE 4E PNG file = 89 50 4E 47 GIF file = 47 49 46 38
the above are the 4-byte headers in Hex(raw) I need to read these headers of any given file using OpenFileDialog using Button1_click event,on selection of any given file(*.* filters ON)it should use the BinaryReader and look for only 4-bytes starting from offset 0, and it should not go to EOF marker (-1).and have a variable to hold this 4-byte header value, to run this in a database table which will check the same header value in the table and would display the corresponding extension of the file. from the table.
I can do this using case, if then...etc.however, I have to do it using Database and also i need to check for testing purpose to use MsgBox() to display this variable which is holding the 4-byte header.however, the MsgBox doesnt allow anything other than String.
I want to Serialize and Deserialize a configuration class containing a Dictionary to a XML file.Here is an exemple of what the class look like.
Imports Public Class
[code]....
When I try to serialize it with a XmlSerializer I get an exception saying to me that it is impossible to serialise Configuration.Parametres because it implements IDictionary.
i made an assembly that contains a class DownloadJob / I load the assembly into another project (the download manager) and i am trying to serialize the downloadjob into a XML file as such:
Public Sub Save() Dim objStreamWriter As New IO.StreamWriter("C:Product.xml") Dim x As New System.Xml.Serialization.XmlSerializer(Me.GetType) x.Serialize(objStreamWriter, Me) objStreamWriter.Close() End Sub
I put the save function in the assembly in the class downloadjob itself so ME refers to the DownloadJob class object that i want to serialize I get this huge exception:
The assembly with display name 'Download Client.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'Download Client.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
[code]....
however when i turn off exceptions serioalization works and i dont have a problem.
I have a form.vb file that has recently became a binary file, instead of text file. That means that I can't compare or merge it anymore. When I try so, I get error message that tells me that the file contains 00' character, but I can't find this character although I searched the whole file
I have three sub tables that I want to process. For each I want to combine the rows, as they are only different by contents in the second column(I want to do the same to the fourth column, later):
I have to generate an XML file from several database tables. I could use the WriteXml method of the DataSet to do it, but the database tables are really huge and I can't add all those tables in the DataSet at the same time or it may cause a problem because of the big amount of memory used. Then I decided to use the DataTable's WriteXml method and save table after table, but the the generated file only stores the information of the last DataTable.WriteXml's call. How can I preserve the previous XML data when adding all that information?
I want to load a csv file (A comma delimited text file) into a datatable. I found the OdbcDataAdapter Class which looks perfect, but it says it is supported only in version 1.1 of the .NET Framework.
Is there a better way to import a csv file into a datatable? the first line has the column headers.
I am using Visual Studio 2008, using version 3.5 of the .NET framework
I am using VB2005 and trying to put an application together.What it needs to do is retrieve information from a binary file, possibly alter that information, and put it back into a new file.The file is a .wav file with data appened to the end. There is an additional section at the end of the .wav file which stores xml data.I have found that if I open this in a hex editor and make a 1:1 swap on any of the bytes that the application that the file is for can still read the XML.If I tried to add or remove characters from the XML then it would not read. I located a header byte and incremented it to resolve this.
This worked as an excellent bandage to do conversions where the data always needed to be changed to the same thing.What I have been asked to do is build logic that allows for different things to happen depending upon what data is contained within the file.The method that I am currently trying to impliment is:
Read through the file with a system.io.binaryreader
Searche for a bytestream that will signal data is coming
For example:
If System.IO.File.Exists("C: est estread.wav") Then Dim findit() As Integer = New Integer() {&H3C, &H55, &H73, &H72, &H44, &H65, &H66, &H30, &H31, &H30} Dim i As Integer[code].....
And then extract all the data till the end of element marker "<" It seemed like there should be a better way and I was looking for some insight. If I proceed with this method, I will have to read the file one time to gather the information and then a second time to write it all out with the header modified for length.This is my first experiene with working with binary files in this way.Also,I've been experiementing with building a string and slapping it back in at the end using the binarywriter.write(string) method.I noticed that it was putting in header characters before the string.These seem to change if I change the length of the string.At one point it was d0 07. Later it became e7 07. Does anyone know of a way to prevent this header from being inserted?
I tried a for each loop to grab all of the characters from the string, convert them to a byte array and deposit the byte array into the file, but the header remained the same. When I write the byte array generated from a system.io.binaryreader I do not get this header.
Dim _tableBackLogs As System.Data.DataTable Do While i - 2 > 0 _tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'") i = i - 2
Doing this replaces the previous data in the DataTable. I want to retain the previous data i.e i want the new rows to be added to the DataTable w/o replacing the previous rows.
I have a Binary file that has data represented in 1604 bytes. each set of data within these groups is composed of short (2 byte) numbers. I would like to creat a vb.net program that takes this binary file then converts it to numbers, and then places it within a new text file. How would I accomplish this?
I have an image stored in the database as varbinary(max) When it's read out into a datatable, it's only being displayed as System.Byte[]. I've tried every trick in the book to get the binary in string format so I can write it back to the varbinary column in another database.
i have a file any type of file and i want to display the binary of that file the (01) of that file can do it also i want to display the hexa which it better and faster if u just can put me on track
I've been using VB.NET for a few years now, but I never really got into binary files. How do you add onto binary files from the beginning? Here is some example code:
Dim writer As New IO.BinaryWriter(IO.File.Open("C:\Users\Dameon\Desktop\newbin.bin", IO.FileMode.CreateNew)) writer.Write("HELLO WORLD!")
[Code]....
How can I add onto the beginning of the file without overwriting what's already there? I'm trying to make my own file archive format. I have the compressing/decompressing down, but now I'm implementing adding/deleting a file after the archive already made.
I need make an application that gets binary code from a file, such as a .exe, (in 8-bit form) and display the charectors in a RichTextBox .BUT! The catch is I need it to do the process REALLY fast, like in a 5th 0.5 of a second. I have a method but it takes way to like, sometimes 5 seconds for 1 file, which isn't what I want This is the code I have:[CODE]......
I am not exactly sure how to say this, but what I want to do is to write a series of strings converted to their hex notation to a binary file. Here is what I have[code]....