i'm working on a voting system but im having problems in adding records... i have two a primary key, the idnumber and the address. the address is where I base if that certain address already voted. but the problem is everytime i try to add a record with the same address (ex. Block 1 lot 4), the data is duplicated which is not output i want. the program should detect that there is already an existing address. i hope you guys can help me.
this is the code i am using
Private Sub AddNewVoter()
Dim li As New ListViewItem
SqlString = "INSERT INTO voter (voterIDno, voterPass, voterLname, voterFname, voterMname, address, contactNo, gender, birthday, civilStatus, voterStatus) VALUES (" & _
"'" & txtidnumber.Text & "'," & _
"'" & txtpassword.Text & "'," & _
"'" & txtlname.Text & "'," & _
"'" & txtfname.Text & "'," & _
"'" & txtmi.Text & "'," & _
"'" & txtaddress.Text & "'," & _
"'" & txtcontactno.Text & "'," & _
"'" & cmbgender.Text & "'," & _
"'" & txtbirthday.Text & "'," & _
"'" & cmbcivilstatus.Text & "'," & _
"'" & cmbvotingstatus.Text & "')"
Using conn As New MySqlConnection(ConnString)
Using cmd As New MySqlCommand(SqlString, conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("voterIDno", txtidnumber.Text)
cmd.Parameters.AddWithValue("voterPass", txtpassword.Text)
cmd.Parameters.AddWithValue("voterLname", txtlname.Text)
cmd.Parameters.AddWithValue("voterFname", txtfname.Text)
cmd.Parameters.AddWithValue("voterMname", txtmi.Text)
cmd.Parameters.AddWithValue("address", txtaddress.Text)
cmd.Parameters.AddWithValue("contactNo", txtcontactno.Text)
cmd.Parameters.AddWithValue("gender", cmbgender.Text)
cmd.Parameters.AddWithValue("birthday", txtbirthday.Text)
cmd.Parameters.AddWithValue("civilStatus", cmbcivilstatus.Text)
cmd.Parameters.AddWithValue("voterStatus", cmbvotingstatus.Text)
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
MsgBox("New voter has been succesfully saved", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "SAVED")
End Sub