3 Replies - 10348 Views - Last Post: 13 August 2009 - 10:44 AM Rate Topic: -----

#1 Christo-swart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-August 09

Voting system in vb.net

Posted 13 August 2009 - 06:00 AM

Help please, I did this first part, but don' know how program the vote BTN. I want the end-user to be able to select the candidate from the dataGrid and then hit vote. It should then save the cast vote to the access Database. I have been struggling with this for about 2 moths now. I am stil a beginner so please bear with me......

Imports System.Data.OleDb
Public Class Form1

	Inherits System.Windows.Forms.Form
	Dim RsSAve As New ADODB.Recordset
	Dim RsSearch As New ADODB.Recordset
	Dim RS, RS1 As New ADODB.Recordset
  

	Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
	End Sub
	Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Call Connection()
		RsSearch = New ADODB.Recordset
		RsSearch.Open("select * from usertable ", CON, 1, 2, )
		RsSearch.MoveFirst()
		Call ShowRecord()
		txtgender.Text = ("Choose to GENDER")
		txtgender.Items.Add("MALE")
		txtgender.Items.Add("FEMALE")
	End Sub
	Public Sub ShowRecord()
		txtserial.Text = RsSearch.Fields("Serial").Value
		txtname.Text = RsSearch.Fields("name").Value
		txtgender.Text = RsSearch.Fields("gender").Value
		txtaddress.Text = RsSearch.Fields("address").Value
		txtcity.Text = RsSearch.Fields("city").Value
		txtstate.Text = RsSearch.Fields("state").Value
		txtphone1.Text = RsSearch.Fields("phone1").Value
	End Sub
	Public Sub clear()
		txtserial.Text = ""
		txtname.Text = ""
		txtgender.Text = ""
		txtaddress.Text = ""
		txtcity.Text = ""
		txtstate.Text = ""
		txtphone1.Text = ""
		If RsSearch.State = 1 Then RsSearch.Close()
		RsSearch.Open("select * from usertable ", Con, 1, 2)
		RsSearch.MoveLast()
		txtserial.Text = RsSearch.Fields("Serial").Value
		txtserial.Text = Val(txtserial.Text) + 1

	End Sub
	Public Sub SaveRecord()

		RsSAve.Fields("Serial").Value = txtserial.Text
		RsSAve.Fields("name").Value = txtname.Text
		RsSAve.Fields("gender").Value = txtgender.Text
		RsSAve.Fields("address").Value = txtaddress.Text
		RsSAve.Fields("city").Value = txtcity.Text
		RsSAve.Fields("state").Value = txtstate.Text
		RsSAve.Fields("phone1").Value = txtphone1.Text
	End Sub

	Private Sub AddNewRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewRecordToolStripMenuItem.Click
		Call clear()
	End Sub

	Private Sub LoadRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadRecordToolStripMenuItem.Click
		Call Connection()
		RsSearch = New ADODB.Recordset
		RsSearch.Open("select * from usertable ", CON, 1, 2, )
		RsSearch.MoveFirst()
		Call ShowRecord()
	End Sub

	Private Sub SaveRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveRecordToolStripMenuItem.Click
		RsSAve = New ADODB.Recordset
		Dim msg
		msg = MsgBox("Are you sure to save this record.....?", MsgBoxStyle.Question + MsgBoxStyle.YesNo)

		If msg = vbYes Then
			RsSAve.Open("Select * from usertable", CON, 1, 2)
			RsSAve.AddNew()
			Call SaveRecord()
			RsSAve.Update()

		End If
	End Sub

	Private Sub UpdatingRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdatingRecordToolStripMenuItem.Click
		RsSAve = New ADODB.Recordset
		RsSAve.Open("select * from usertable where Serial=" & Trim(txtserial.Text) & "", CON, 1, 2)
		Call SaveRecord()
		RsSAve.Update()
		MsgBox("Record update successfully......")
	End Sub

	Private Sub DeleteRecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteRecordToolStripMenuItem.Click
		On Error Resume Next
		Dim Ans
		Ans = MsgBox("Are you sure to delete this record....?", vbYesNo + vbQuestion)
		If Ans = vbYes Then
			CON.Execute("delete from UserTable where Serial=" & Trim(txtserial.Text) & "")
			RsSearch.MovePrevious()
			Call clear()
			Call ShowRecord()

		End If
	End Sub

	Private Sub first_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles first.Click
		On Error Resume Next
		RsSearch.MoveFirst()
		Call ShowRecord()
	End Sub

	Private Sub prev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles prev.Click
		On Error Resume Next
		RsSearch.MovePrevious()
		Call ShowRecord()
	End Sub

	Private Sub Nex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nex.Click
		On Error Resume Next
		RsSearch.MoveNext()
		Call ShowRecord()
	End Sub

	Private Sub last_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles last.Click
		On Error Resume Next
		RsSearch.MoveLast()
		Call ShowRecord()
	End Sub
	Public Function OnlyCharacter(ByVal key As String) As Boolean
		If ((key >= 65 And key <= 90) Or (key >= 97 And key <= 122) Or key = 8) Then

			OnlyCharacter = False
		Else
			MsgBox("only enter the value of character")
			OnlyCharacter = True
		End If
	End Function
	Public Function OnlyNumeric(ByVal Key As String) As Boolean
		If (Key >= 48 And Key <= 57) Or Key = 8 Then
			OnlyNumeric = False
		Else
			MsgBox("only enter the value of Number")
			OnlyNumeric = True
		End If
	End Function

	Private Sub txtphone1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtphone1.KeyPress
		e.Handled = OnlyNumeric(Asc(e.KeyChar))
	End Sub

	Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtname.KeyPress
		e.Handled = OnlyCharacter(Asc(e.KeyChar))
	End Sub

	Private Sub txtcity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcity.KeyPress
		e.Handled = OnlyCharacter(Asc(e.KeyChar))
	End Sub

	Private Sub txtstate_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtstate.KeyPress
		e.Handled = OnlyCharacter(Asc(e.KeyChar))
	End Sub

	Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click
		If txtsearch.Text = "" Then MsgBox("Please type Item Name", MsgBoxStyle.Critical, "Enter Text") : Exit Sub

		Dim MYDA As OleDbDataAdapter = New OleDbDataAdapter
		Dim MYDS As DataSet = New DataSet

		RS = New ADODB.Recordset
		RS.Open("SELECT * FROM usertable WHERE name LIKE '" & txtsearch.Text & "%' ", CON, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

		MYDA.Fill(MYDS, RS, "ITEM")
		DataGrid1.DataSource = MYDS.Tables(0)

	End Sub

	Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
		Call clear()
	End Sub

	Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
		End
	End Sub

	Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

	End Sub

	Private Sub DataGrid1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.CellContentClick

	End Sub
End Class


Mentor Edit: :code:

Attached image(s)

  • Attached Image

This post has been edited by AdamSpeight2008: 13 August 2009 - 06:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Voting system in vb.net

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9049
  • View blog
  • Posts: 33,976
  • Joined: 12-June 08

Re: Voting system in vb.net

Posted 13 August 2009 - 06:47 AM

Sooooo what part are you having problems with? The inserting into a database? Handling the button click?
Was This Post Helpful? 0
  • +
  • -

#3 Christo-swart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-August 09

Re: Voting system in vb.net

Posted 13 August 2009 - 09:37 AM

View Postmodi123_1, on 13 Aug, 2009 - 05:47 AM, said:

Sooooo what part are you having problems with? The inserting into a database? Handling the button click?


Both actually, but more with the "inserting into a database" part. This is a college project. I had to design a student voting system where students vote for SRC's the whole system is working except for the voting part.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9049
  • View blog
  • Posts: 33,976
  • Joined: 12-June 08

Re: Voting system in vb.net

Posted 13 August 2009 - 10:44 AM

Do you know how to write an insert statement in SQL?

The .NET code would go like:
1. create connection to access.
2. open connection.
3. have string that contains your insert statement
4. make an oledb command object.. set the params to the connection string and your insert string
5. on that command object use the executeNonQuery to try and run your insert.
6. catch errors as needed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1