Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:00:58+00:00 2026-06-14T10:00:58+00:00

I have a DataBound DGV it has 3 Columns namely ID(not pk) , Name

  • 0

I have a DataBound DGV it has 3 Columns namely ID(not pk), Name, and Status. I have 2 Buttons Add and Post. Add, adds Data to the DGV and DataBase(MySql) but in Status, it adds "No". What I want to do is for example I have 3 Rows in my DGV and highlight those 3 and click Post, the value in Status will be changed to "Yes". Here is what I have done so far, but I’m having trouble with the syntax for the UPDATE QUERY. THIS CODE WORKS NOW

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the TestDataSet.testing table. You can move, or remove it, as needed.
        Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
        Using _conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = test")

            Using cmd
                With cmd
                    MsgBox("Connection Established")
                    .Connection = _conn
                    .Parameters.Clear()
                    .CommandText = "Select Max(TransactionID) from testing"
                    _conn.Open()
                    Dim dr As MySqlDataReader
                    dr = cmd.ExecuteReader()
                    If dr.Read() Then
                        If IsDBNull(dr.Item(0)) Then
                            txtNumber.Text = "1"
                        Else

                            txtName.Text = dr(0).ToString() + 1
                        End If

                    End If
                End With
            End Using
        End Using

        FillGrid()

    End Sub

    Private Sub FillGrid()



        Using _conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = test")
            Using _comm As New MySqlCommand
                With _comm
                    .CommandText = " SELECT `ID`, `TransactionID`, `Name`, `Posted` FROM `testing`"
                    .Connection = _conn
                End With
                Using _adapter As New MySqlDataAdapter(_comm)
                    Try
                        _conn.Open()
                        Dim _ds As New DataSet
                        _adapter.Fill(_ds)
                        GVTransaction.DataSource = _ds.Tables(0)
                    Catch ex As Exception

                    End Try
                End Using
            End Using
        End Using
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Using conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = test")
            Using cmd
                With cmd
                    MsgBox("Connection Established")
                    .Connection = conn
                    .Parameters.Clear()
                    .CommandText = "INSERT INTO testing(TransactionID, Name, Posted) VALUES (@ID, @iName, @iPosted)"
                    .Parameters.Add(New MySqlParameter("@ID", txtNumber.Text))
                    .Parameters.Add(New MySqlParameter("@iName", txtName.Text))
                    .Parameters.Add(New MySqlParameter("@iPosted", "No"))


                End With
                Try
                    conn.Open()
                    cmd.ExecuteNonQuery()
                Catch ex As MySqlException
                    MsgBox(ex.Message.ToString())
                End Try
            End Using
        End Using

        MsgBox("Data Added to the Database")

        Me.TestingTableAdapter.Dispose()

        Me.TestingTableAdapter.Fill(Me.TestDataSet.testing)
    End Sub

    Private Sub btnPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPost.Click


        Dim _ID As New List(Of String)
        Dim _Name As New List(Of String)
        For Each _x As DataGridViewRow In TestingDataGridView.SelectedRows
            _ID.Add(_x.Cells("GVTransactionID").Value.ToString())
            _Name.Add("'" & _x.Cells("GVName").Value.ToString() & "'")
        Next
        Dim inClause As String = String.Join(",", _ID.ToArray())
        Dim inClause1 As String = String.Join(",", _Name.ToArray())
        Dim _sqlUpdate As String = String.Format("UPDATE testing SET Posted = @Posted WHERE TransactionID IN ({0}) AND Name IN ({1})", inClause, inClause1)

        Using _conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = test")
            Using _commm As New MySqlCommand()
                With _commm
                    .CommandText = _sqlUpdate
                    .Connection = _conn
                    .CommandType = CommandType.Text
                    .Parameters.AddWithValue("@Posted", "YES")

                End With
                Try
                    _conn.Open()
                    _commm.ExecuteNonQuery()
                    FillGrid()
                Catch ex As MySqlException
                    MsgBox(ex.StackTrace.ToString)
                End Try

            End Using
        End Using
    End Sub
End Class

Any Helps or tips is greatly appreciated. Please and Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:00:59+00:00Added an answer on June 14, 2026 at 10:00 am

    Try this one,

    Dim _ID As New List(Of String) 
    Dim _Name As New List(Of String) 
    For Each _x As DataGridViewRow In TestingDataGridView.SelectedRows  
       _ID.Add(_x.Cells("TransactionID").Value.ToString())
       _Name.Add("'" & _x.Cells("Name").Value.ToString() & "'")
    Next 
    
    Dim inClause As String = String.Join(",", _ID.ToArray()) 
    Dim inClause1 As String = String.Join(",", _Name.ToArray()) 
    Dim _sqlUpdate As String = String.Format("UPDATE testing SET Posted = @Posted WHERE TransactionID IN ({0}) AND Name IN ({1})", inClause, inClause1)
    
    Using _conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = test")
        Using _comm As New MySqlCommand()
            With _comm
              .CommandText = _sqlUpdate
              .Connection = _conn
            End With
            Try
                _conn.Open()
                _comm.ExecuteNonQuery()
            Catch ex As MySqlException
                MsgBox(ex.Message.ToString())
            End Try
    
        End Using
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a databound listbox which is actually displaying two columns of data. It
I have a databound dgv that contains combobox columns. When the user selects an
I have a non databound DGV (no datasource, etc; rows added manually). To filter
I have a window that is databound to a ViewModel. The ViewModel has many
i have a gridview witch contain 4 databound columns and 2 templated column. in
I have a ListBox which is databound to an ObservableCollection and has a complex
I have a databound DataGridView. The data source is a typed data set with
I have a databound button that has a TargetNullValue: <Button Content={Binding Path=NextItem, Mode=OneWay, TargetNullValue='None'}
I have a databound calendar control that loads the date from the database. The
I have a databound and itemtemplated ListBox: <ListBox x:Name=lbLista ScrollViewer.VerticalScrollBarVisibility=Visible> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.