im creating a voting system that add votes to the database but it seems that my update/submit button don't add numbers(INT) in my database. what could be the problem here?help

my database schema:

| cid | cpos       | cfname | cmname | clname | cyr | cparty | votes |
|  1  | President  | john   | ark    |  smith | 3   | glory  |       |





Imports MySql.Data.MySqlClient
Public Class Form4

Dim con As New MySqlConnection
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.ConnectionString = ("server=localhost;user id=root;database=db")
    Try
        con.Open()

        With cmd
            .Connection = con
            .CommandText = "SELECT CONCAT_WS(' ', cid, cfname, cmname, clname, cparty) as cid, " & _
                           "cpos, cid from candidate WHERE cpos='Vice President' OR " & _
                           "cpos='President' OR " & _
                           "cpos='Secretary' OR " & _
                           "cpos='Treasurer' OR " & _
                           "cpos='Auditor' OR " & _
                           "cpos='Public Information Officer' OR " & _
                           "cpos='Peace Officer'"
        End With
        Dim dt As New DataTable

        da.SelectCommand = cmd
        da.Fill(dt)
        With ComboBox1
            Dim dv = New DataView(dt, "cpos='President'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv
        End With
        With ComboBox2
            Dim dv1 = New DataView(dt, "cpos='Vice President'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv1
        End With
        With ComboBox3
            Dim dv2 = New DataView(dt, "cpos='Secretary'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv2
        End With
        With ComboBox4
            Dim dv3 = New DataView(dt, "cpos='Treasurer'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv3
        End With
        With ComboBox5
            Dim dv4 = New DataView(dt, "cpos='Auditor'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv4
        End With
        With ComboBox6
            Dim dv5 = New DataView(dt, "cpos='Public Information Officer'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv5
        End With
        With ComboBox7
            Dim dv6 = New DataView(dt, "cpos='Peace Officer'", "", DataViewRowState.CurrentRows)
            .DisplayMember = "cid"
            .ValueMember = "cid"
            .DataSource = dv6
        End With


    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    con.Close()
End Sub

Private Sub cmdsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsubmit.Click


    Dim Query As String
    Query = "Update candidate SET votes = votes + 1 WHERE cid = '" & ComboBox1.SelectedValue.ToString() & "')"

    Dim cmd As MySqlCommand = New MySqlCommand(Query, con)

    Try
        cmd.ExecuteNonQuery()
    Catch ex As Exception
    End Try
    Dim ds As New DataSet
    Dim dt As New DataTable

    da.Update(dt)
    MessageBox.Show("Query Completed")
End Sub
End Class

I'm assuming that cid is an integer, so remove the single quotes around ComboBox1.SelectedValue.ToString()...

So this...Query = "Update candidate SET votes = votes + 1 WHERE cid = '" & ComboBox1.SelectedValue.ToString() & "')"

Should Be... Query = "Update candidate SET votes = votes + 1 WHERE cid = " & ComboBox1.SelectedValue.ToString() & ")"

This article has been dead for over six months. Start a new discussion instead.