H
H
Hosting Yaroslavl2019-02-08 13:04:17
Visual Basic
Hosting Yaroslavl, 2019-02-08 13:04:17

How to save data from DataGridView1 back to database (connect via Odbc)?

Connect data to control

Dim MyConString As String = StringConnectToBDMySQL(driver_mysql, options_server, options_database, options_user, options_password, "3")

        ' Производим попытку соединения
        Try
            adapter = New OdbcDataAdapter(strSQL, MyConString)
            adapter.MissingMappingAction = MissingMappingAction.Passthrough
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        Catch ex As Exception
            MsgBox("connection: " & ex.Message)
            'Return False
        End Try



        Dim DataSet1 As DataSet = New DataSet

        Try
            adapter.Fill(DataSet1, "table")
        Catch ex As Exception
            MsgBox("fill: " & ex.Message)
            'Return False
        End Try

        Dim Workview As DataView = DataSet1.Tables("table").DefaultView
        DataGridView1.DataSource = Workview

How can I save the changes back to the database using the button, something
like: adapter.update
() .to. I connect the data in a separate procedure and the button will be in the form. Is it possible to somehow do everything by referring only to DataGridView1 or do I need to make a global variable adapter or DataSet1 and do everything through them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-02-08
@tsklab

something like: adapter.update()
There is: DbDataAdapter.Update Method .
Extra: IDEs usually have code insight that can suggest methods and properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question