December 5, 2016

Update SQL via Gridview

Hi there. so i’ve searched around to find how to update my sql database via gridview round a lot of examples but didn’t make it :/ here’s the code.. all i need is an update “button” or something.

Dim connectionString As String = "Server=localhost; User Id=?; Password=?; Database=?"
    Dim SQLConnection As MySqlConnection = New MySqlConnection
    Dim ds As New DataSet
    Dim adapter As New MySqlDataAdapter
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0

        SQLConnection = New MySqlConnection()
        SQLConnection.ConnectionString = connectionString

            If SQLConnection.State = ConnectionState.Closed Then
                ToolStripStatusLabel1.Text = "Database Connection Sccessfully Established"
                ToolStripStatusLabel1.Text = "Database Connection Terminated"

            End If
            Using SQLConnection As New MySqlConnection(connectionString)
                Dim sqlCommand As New MySqlCommand()
                With sqlCommand
                    .CommandText = "select * from users"
                    .Connection = SQLConnection
                    .CommandType = CommandType.Text

                End With
                    Dim table As DataTable
                    adapter = New MySqlDataAdapter(sqlCommand)
                    ds = New System.Data.DataSet()
                    adapter.Fill(ds, "users")
                    table = New DataTable
                    DataGridView1.DataSource = ds.Tables(0)

                Catch ex As MySqlException

                End Try
            End Using

        Catch ex As Exception

        End Try
    End Sub

Category : Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by Bolkya Resha and Software Testing Theme