Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Monday, August 8, 2011

VB-88 : Vote gained by the Candidate(Polling Application)

==================================================================================

Before going to do any Database Program ,Click here to  understand Database Concepts thoroughly.


That is , Creating Database within VB Platform


==================================================================================

Simulate a simple polling application and draw the results basing upon the votes gained by the individual candidates.Assumptions can be made wherever necessary.

(A)Program Design : 


(B) Property(Controls Used) :
  • One OptionButton (Name-Option1) , Index= 0 to 12 (For selecting particular candidate)
  • One Label(Label1) , Index= 0 to 12 (Displays the name of the candidate)
  • One Command Button Give vote 

(C) Attaching Code to the Object :


Open Explicitcn For Random As New ADODB.Connection
Public rs As New ADODB.Recordset
Dim rs As String
Dim names As String
Dim i As Integer
Dim Index As String
Private Sub Command1_Click()
If rs.State = 1 Then
rs.Close
End If

rs.Open "update PollingApp set TotalVotes=TotalVotes+1 where CandidateName="" & Option1.Item(indexName).Caption & "",cn,adOpenDynamic,adLockOptimistic"

If rs.State = 1 Then
rs.Close
End If

rs.Open "select*from PollingApp", cn, adOpenDynamic, adLockOptimistic
For i = 0 To Option1.Count - 1
Option1(i).Caption = "Number of Votes are" & rs("TotalVotes")
rs.MoveNext
End Sub
Private Sub Form_Load()
cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial"
Catalog = Database: Data Source = "U5W4G8"
cn.CursorLocation = adUseClient
If rs.State = 1 Then
rs.Close
End If

rs.Open "select*from PollingApp", cn, adOpenDynamic, adLockOptimistic
For i = 0 To Option1.Count - 1
Label1(i).Caption = "Number of Votes are" & rs("TotalVotes")
rs.MoveNext
Next
End Sub
Private Sub Option1_Click(Index As Integer)
names = Option1.Item(Index).Caption
indexName = Index
End Sub



      • ====================================================================
        Back to Home   &  VB
    ===========================================================

    No comments: