Serializing
-
Does anyone know how to save entries from a form to a file so they can be accessed for later viewing? I need to be able to pull the saved data back to the form it was saved from for later use. If anyone could help me with this I'd appreciate it. Thanks, ccotton333
-
Does anyone know how to save entries from a form to a file so they can be accessed for later viewing? I need to be able to pull the saved data back to the form it was saved from for later use. If anyone could help me with this I'd appreciate it. Thanks, ccotton333
If you are using a Windows Form, you could bind your "entries" (textboxes and other controls, I suppose) to a DataSet, and then use the WriteXML() and ReadXML() DataSet methods to serialize/deserialize it on a disk file.
-
Does anyone know how to save entries from a form to a file so they can be accessed for later viewing? I need to be able to pull the saved data back to the form it was saved from for later use. If anyone could help me with this I'd appreciate it. Thanks, ccotton333
I would just save toa text file. Then you could read from the file to restore the valus. It is easy. You need System.io an duse stream reader and stream writer. I have a logon form which is check for a saved user name from a file at load. And on Enter I save the user name to this same file. That way the user name is remembered when the program is ended and then restarted. Ex. ( sName4User is global variable, Private Sub frmLogon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' This will retreive a user name from file if present. ' Opens a file stream for reading Dim myFS As New FileStream("c:\winnt\Temp\User.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.None) Dim myReader As New StreamReader(myFS) ' Assigning a reader sName4User = myReader.ReadLine 'Retreives username If Not sName4User Is Nothing Then txtName.Text = sName4User End If myReader.Close() End Sub Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click 'Storing username to file and closing if a username was entered If txtName.Text <> "" Then sName4User = txtName.Text ' Opens a file stream for reading Dim myFS As New FileStream("C:\winnt\Temp\User.txt", FileMode.OpenOrCreate) Dim myWriter As New StreamWriter(myFS) ' Assinging a reader myWriter.WriteLine(sName4User) ' Storing to the file myWriter.Close() Me.DialogResult = DialogResult.OK Else txtName.Text = "Enter a user name" txtName.Focus() txtName.SelectAll() End If End Sub