Results 1 to 8 of 8

Thread: [RESOLVED] Updating Mysql database with vb datagridview

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    8

    Resolved [RESOLVED] Updating Mysql database with vb datagridview

    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!
    Last edited by Siddharth Rout; May 10th, 2013 at 02:24 PM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width