Best storage method

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

HI, I have two sets of data, the largest set of data contains 370 rows...
both sets only have two columns. I want to be able to distribute the data
with my applaction. The other option, would be to have the data as seprate
file(easier if needs updating), but I don't what the user to be able to read
the file, just my program should be able to read the file.
Any ideas on the best method?
thanks,
Brian
 
Brian said:
HI, I have two sets of data, the largest set of data contains 370 rows...
both sets only have two columns. I want to be able to distribute the data
with my applaction. The other option, would be to have the data as
seprate file(easier if needs updating), but I don't what the user to be
able to read the file, just my program should be able to read the file.
Any ideas on the best method?
thanks,
Brian
Have you thought about encrypting the data in the file?
 
If you want to persist the state of a DataSet to your application at a later
time, I'd look up binary serialization. It will save your dataset to a file
in binary format (unreadable by people) You can Google "VB.NET binary
serialization" but the jist of it is:

Dim objDS As DataSet = New DataSet()
' Populate dataset

Dim S As Stream = File.Open("MyDS.bin", FileMode.Create,
FileAccess.ReadWrite)
Dim BF As BinaryFormatter = New BinaryFormatter()
BF.Serialize(S, objDS)
S.Close()

When you deserialize it, you'll have your dataset back in the same state you
left it. If your data is sensitive, I'd encrypt it first because any program
will be able to deserialize your object back into a dataset.
 
Thanks, works pretty good.
i was trying this with just a few simple textboxes... then I thought I'd try
to encrypt it.
I was thinking the best way to do this was to encryp the string before the
binaryformatter, but i dont't a difference in the find between encrypted and
standard text.
i was reading through and using the example at
http://www.devarticles.com/c/a/VB.Net/String-Encryption-With-Visual-Basic-.NET/3/
but instead of creating a memory stream, I passed byval the filestream.
Is it best to encrypt the binary or the string? Not sure, and have not
tried to, encrypt the binary and that really does not make much since to me.
Any possibly helpful thoughts
Brian
 
I think the best approach would be to serialize the DataSet to XML in memory
(in other words, convert your dataset into a string) and then encrypt the
string, THEN serialize the encrypted string into a binary format. It would
look something like this (note, I'm just hammering this out ad hoc, I
haven't tested it):

Private Sub EncryptDataSet(DS As DataSet)
Dim XMLData As StringBuilder = New StringBuilder()
Dim Writer As StringWriter = New StringWriter(XMLData)

DS.WriteXML(writer)

' You'll need to write the EncryptString function to do the actual
encryption
Dim EncryptedData As String = EncryptString(strKey, XMLData.ToString())

Dim S As Stream = File.Open("MyDS.bin", FileMode.Create,
FileAccess.ReadWrite)
Dim BF As BinaryFormatter = New BinaryFormatter()
BF.Serialize(S, EncryptedDate)
S.Close()
End Sub

Decrypting it would just be the reverse. Deserialize the file into memory,
decrypt the string, load it into a DataSet using the DataSet.ReadXml method
and you've got your DataSet back.
 
Back
Top