Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

Updating Mysql database with vb datagridview

$
0
0
Hi!

I am creating a windows form with vb to edit a mysql database. I have a datagridview where i can view the database with custom queries. But, I want to save the edited cells back to the source database in their respective places. I dont know how to do that. Any help is appreciated. I am attaching my code:

Code:

Imports MySql.Data.MySqlClient

Private Sub showdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles showdata.Click

    Dim uspatserver As String = "server = localhost; user id = ****; password = ****; database = us_pat"
    Dim uspatconnection As MySqlConnection = New MySqlConnection

        datagrid.Columns.Clear()

     
        Dim cmd As MySqlCommand = New MySqlCommand
        Dim stm As String

        If uspatconnection.State = ConnectionState.Closed Then
            uspatconnection.Open()
        End If

        stm = "SELECT * FROM clinicalinfo"
             
        cmd.CommandType = CommandType.Text
        cmd.CommandText = stm
        cmd.Connection = uspatconnection

        Dim dt As New DataTable
        dt.Load(cmd.ExecuteReader)

        With datagrid
            .AutoGenerateColumns = True
            .DataSource = dt
        End With

       
        cmd.Dispose()
        cmd = Nothing
        uspatconnection.Close()
        uspatconnection.Dispose()

    End Sub


Thanks!

Viewing all articles
Browse latest Browse all 42220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>