locked
Save multiple results of a stopwatch RRS feed

  • Question

  • I've written a stopwatch program that works just fine and added a recall function to it so when someone pushes the save button it stores the iniger values for hour miniute and second as application level user defineable variables ie... My.Settings.Hour but that only works for one time.  I want to be able to save more than one setting, i was thinking that the text value of the label in displaing the current value  of the stopwatch could be dropped into a SQL database when the user hits the Save button on the form.  But what im getting stuck on if i got this way is getting the save button to add a new record and how to recall it.  If anybody knows a simpler way of saving the user data i'd try that as well

    Sunday, July 6, 2008 7:27 PM

Answers

  • Hi Geoffrey,

    I recommend that you create a datatable to generate the XML file to persist the data. After you need to add the new record, just add a datarow to datatable. By using the datatable object, you can implement the search, sort functionalities easily. Try using the datatable object.

    Public Class Form1

        Dim dt As DataTable

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            dt = New DataTable

            dt.TableName = "table1"

            dt.Columns.Add("id", GetType(Integer))

            dt.Columns.Add("name", GetType(String))

            dt.Columns("id").Unique = True

            If (System.IO.File.Exists("datatable_serialization.xml")) Then

                dt.ReadXml("datatable_serialization.xml")

            Else

                For i As Integer = 0 To 10

                    dt.Rows.Add(i, "name " & i.ToString)

                Next

            End If

            DataGridView1.DataSource = dt

        End Sub

        Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

            If (dt IsNot Nothing) Then

                dt.WriteXml("datatable_serialization.xml")

            End If

        End Sub

    End Class


    If you need to save the data to the database, you need to use the SqlCommand( or Oledbcommand) to issue the Insert statement to save the data into the database, visit here for your reference.

    Best regards,
    Riquel
    Wednesday, July 9, 2008 12:48 PM
    Moderator