Как сохранить изменения? - PullRequest
       10

Как сохранить изменения?

0 голосов
/ 05 апреля 2019

В моем коде все функции работают хорошо: кнопка сохранения, обновления и удаления фактически работает, но когда я закрываю программу и открываю ее снова, все изменения исчезают.
Таким образом, кнопка Save работает, когда я открываю программутолько;Я хочу, чтобы, когда я что-то изменил, это изменилось и в коде.

Кстати, данные содержатся в DataGridView.

Imports System.Data.DataTable

Public Class Form1
    Dim table As New DataTable("Table")
    Dim index As Integer

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

        table.Columns.Add("ID", Type.GetType("System.Int32"))
        table.Columns.Add("First Name", Type.GetType("System.String"))
        table.Columns.Add("Last Name", Type.GetType("System.String"))
        table.Columns.Add("Age", Type.GetType("System.Int32"))
        table.Columns.Add("Programming", Type.GetType("System.Int32"))
        table.Columns.Add("Law", Type.GetType("System.Int32"))
        table.Columns.Add("English", Type.GetType("System.Int32"))
        table.Columns.Add("GPA", Type.GetType("System.Int32"))
        table.Columns.Add("Grade", Type.GetType("System.string"))

        table.Rows.Add(1, "XXXX", "YYYYY", 21, 88, 77, 90, 89)
        table.Rows.Add(2, "SSDD", "hGSQ", 33, 70, 96, 72, 82)
        table.Rows.Add(3, "fgfgd", "jgfdd", 53)
        table.Rows.Add(4, "cvfghyghj", "sdrgtyh", 19)
        table.Rows.Add(5, "hghfd", "ghjgdf", 36)
        table.Rows.Add(6, "cvvdfgh", "juyrfdvc", 63)
        table.Rows.Add(7, "aefht", "cvfhytrff", 21)
        table.Rows.Add(8, "wghyuj", "mihgdwrh", 33)
        table.Rows.Add(9, "qsztii", "bvdhjh", 53)
        table.Rows.Add(10, "rytyufd", "esdfzr", 19)

        DataGridView1.DataSource = table
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Table.rows.Add(TextBoxID.Text, TextBoxFN.Text, TextBoxLN.Text, TextBoxAGE.Text)
        DataGridView1.DataSource = table
    End Sub

    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBoxAGE.TextChanged

    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick, DataGridView1.CellClick
        index = e.RowIndex
        Dim selectedRow As DataGridViewRow
        selectedRow = DataGridView1.Rows(index)
        TextBoxID.Text = selectedRow.Cells(0).Value.ToString()
        TextBoxFN.Text = selectedRow.Cells(1).Value.ToString()
        TextBoxLN.Text = selectedRow.Cells(2).Value.ToString()
        TextBoxAGE.Text = selectedRow.Cells(3).Value.ToString()
        TextBoxPro.Text = selectedRow.Cells(4).Value.ToString()
        TextBoxLaw.Text = selectedRow.Cells(5).Value.ToString()
        TextBoxENGL.Text = selectedRow.Cells(6).Value.ToString()
        TextBoxGPA.Text = selectedRow.Cells(7).Value.ToString()
        TextBoxGrade.Text = selectedRow.Cells(8).Value.ToString()
    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
        Dim newDataRow As DataGridViewRow

        newDataRow = DataGridView1.Rows(index)

        newDataRow.Cells(0).Value = TextBoxID.Text
        newDataRow.Cells(1).Value = TextBoxFN.Text
        newDataRow.Cells(2).Value = TextBoxLN.Text
        newDataRow.Cells(3).Value = TextBoxAGE.Text
    End Sub

    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        DataGridView1.Rows.RemoveAt(index)
    End Sub
End Class
...