输入投票复选框后可以更新数据库(ms。访问)

时间:2017-11-09 04:59:48

标签: vb.net winforms ms-access

这是登录系统的代码

Imports System.Data.OleDb
Module koneksi
    Public conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\pemilu.accdb")
    Public da As OleDbDataAdapter
    Public ds As DataSet
    Public cmd As OleDbCommand
    Public rd As OleDbDataReader
    Public dgv As New DataGridView
End Module
Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PasswordTextBox.UseSystemPasswordChar = True
        NimTextBox.Focus()
    End Sub

    Private Sub btnpilih_Click(sender As Object, e As EventArgs) Handles btnpilih.Click
        conn.Close()
        conn.Open()
        cmd = New OleDbCommand("SELECT * FROM pemilih WHERE nim = '" &
                           NimTextBox.Text & "' AND password = '" &
                           PasswordTextBox.Text & "'", conn)
        rd = cmd.ExecuteReader
        Dim userfound As Boolean = False
        Dim firstname As String = ""
        Dim lastname As String = ""

        While rd.Read
            If NimTextBox.Text = rd("nim").ToString And PasswordTextBox.Text = rd("password").ToString Then
                userfound = True
                firstname = rd("firstname").ToString
                lastname = rd("lastname").ToString
            End If
        End While

        If userfound = True Then
            MsgBox("Pilihlah Pemimpin Sesuai Hati Nurani Anda. Selamat Memilih.", MsgBoxStyle.Information, "Selamat Memilih")
            NimTextBox.Text = ""
            PasswordTextBox.Text = ""
            Form1.Label1.Text = "Selamat Memilih, " & firstname & " " & lastname
            Me.Hide()
            Form1.Show()
        Else
            MsgBox("Maaf, NIM Atau Password Anda Masukkan Salah Atau NIM Anda Belum Terdaftar. Silahkan Ulangi Kembali.", MsgBoxStyle.Information, "Info")
            NimTextBox.Focus()
        End If
    End Sub

    Private Sub PasswordTextBox_Keypress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles PasswordTextBox.KeyPress
        If e.KeyChar = Chr(13) Then
            btnpilih_Click(Me, EventArgs.Empty)
        End If

    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            PasswordTextBox.UseSystemPasswordChar = False
        Else
            PasswordTextBox.UseSystemPasswordChar = True
        End If
    End Sub
End Class

This is the database of login system.

This is the login form.

它发挥得最好。

这是投票代码

Imports System.Data.OleDb
Public Class Form1
    Private Sub btnpilih_Click(sender As Object, e As EventArgs) Handles btnpilih.Click
        conn.Close()
        conn.Open()

        If ckagus.Checked And cksuyamto.Checked And ckfarid.Checked Then
            MsgBox("Anda hanya bisa memilih satu kandidat", MsgBoxStyle.Information, "Info")
        ElseIf ckagus.Checked And cksuyamto.Checked Then
            MsgBox("Anda hanya bisa memilih satu kandidat", MsgBoxStyle.Information, "Info")
        ElseIf ckagus.Checked And ckfarid.Checked Then
            MsgBox("Anda hanya bisa memilih satu kandidat", MsgBoxStyle.Information, "Info")
        ElseIf cksuyamto.Checked And ckfarid.Checked Then
            MsgBox("Anda hanya bisa memilih satu kandidat", MsgBoxStyle.Information, "Info")
        ElseIf ckagus.Checked Then
            cmd = New OleDbCommand("UPDATE kandidat SET [agus] = agus + 1", conn)
            cmd.ExecuteNonQuery()
            MsgBox("Terimakasih karena sudah memilih", MsgBoxStyle.Information, "Info")
            Me.Hide()
            Form2.Show()
            Form2.NimTextBox.Focus()
        ElseIf cksuyamto.Checked Then
            cmd = New OleDbCommand("UPDATE kandidat SET [suyamto] = suyamto + 1", conn)
            cmd.ExecuteNonQuery()
            MsgBox("Terimakasih karena sudah memilih", MsgBoxStyle.Information, "Info")
            Me.Hide()
            Form2.Show()
            Form2.NimTextBox.Focus()
        ElseIf ckfarid.Checked Then
            cmd = New OleDbCommand("UPDATE kandidat SET [farid] = farid + 1", conn)
            cmd.ExecuteNonQuery()
            MsgBox("Terimakasih karena sudah memilih", MsgBoxStyle.Information, "Info")
            Me.Hide()
            Form2.Show()
            Form2.NimTextBox.Focus()
        End If
        ckagus.CheckState = CheckState.Unchecked
        cksuyamto.CheckState = CheckState.Unchecked
        ckfarid.CheckState = CheckState.Unchecked
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Label1.Text = "Selamat Memilih, Admin " Then
            btnreport.Visible = True
        End If
    End Sub
End Class

This is the database to count the point of candidate

This is the form of voting

问题是:

  1. 根据投票代码,当我选择候选人时,我无法对kandidat表上的值字段求和。
  2. 我的代码错了吗?但是,当我运行程序时没有错误,并且kandidat表的值永远不会增加。 ???

0 个答案:

没有答案