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 >> it does not work. Is it possible to serialize datarows and add it the binary file ?
My Code:
Function GetTable() As DataTable
Dim table As New DataTable ' Create new DataTable instance.
table.Columns.Add("Dosage", GetType(Integer)) ' Create four typed columns in the DataTable.
table.Columns.Add("Drug", GetType(String))
table.Columns.Add("Patient", GetType(String))
table.Columns.Add("Date", GetType(DateTime))
' Add five rows with those columns filled in the DataTable.
table.Rows.Add(25, "Indocin", "David", DateTime.Now)
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now)
Return table
End Function
Private Sub SaveDataTabletoBinary()
dt = GetTable()
Dim format As New Binary.BinaryFormatter
Dim ds As New DataSet
' ds = DataGridView1.DataSource
Using fs As New FileStream("c:\sar1.txt", FileMode.Append)
dt.RemotingFormat = SerializationFormat.Binary
'Other option is SerilaizationFormat.XML
format.Serialize(fs, ds)
End Using
End Sub
Thanks