0

hi !! my background in vb.net is not that good, but i need to make a voting system, user must be log in once and update his status into yes after voting, i have a table namely tbl_elemvoters it has a fields : voterid, username, password, name, grade, section and voted.
on the field voted, it contains 'no' , then after they login the field voted that contains no will updated to yes.

here is my code:

    conn.ConnectionString = "Server=localhost;User Id=root;Passsword=;Database=voting "


    Try
        conn.Open()

    Catch myerror As MySqlException
        MsgBox("error")

    End Try


    Dim myAdapter As New MySqlDataAdapter

    Dim myCommand As New MySqlCommand()
    myCommand.Connection = conn

    myAdapter.SelectCommand = myCommand

    If Textuser.Text = "" And Textpass.Text = "" Then
        MsgBox("invalid")
    ElseIf myCommand.CommandText = "SELECT * FROM tbl_elemvoters WHERE Username = '" + Textuser.Text + "' AND VoterID='" + Textpass.Text + "UPDATE Voted='" + "Yes"
            Form2.Show()
            Me.Hide()

update doesnt working, im confused ;'(.
thanks for the help

Edited by aning0420

3
Contributors
2
Replies
18
Views
4 Years
Discussion Span
Last Post by Keerthi_1
0

what is adapter for? if you want to update your voted field you can do like this :

If Textuser.Text = String.Empty And Textpass.Text = String.Empty Then
            MsgBox("Invalid")
Else
            Try
                Using conn As New MySqlConnection("server=localhost;user=root;password=;database=voting")
                    conn.Open()
                    Dim command As New MySqlCommand("UPDATE tbl_elemvoters SET Voted = 'yes' WHERE Username = @Username AND VoterID = @VoterID", conn)
                    With command.Parameters
                        .AddWithValue("@Username", Textuser.Text)
                        .AddWithValue("@VoterID", Textpass.Text)
                    End With
                    command.ExecuteNonQuery()
                    command.Dispose()
                    conn.Close()
                    Form2.Show()
                    Me.Hide()
                End Using
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
End If

Edited by artemix22

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.