Hi Team,
I understand that there are numerous number of Articles with the following Title and I should have gone through them before posting but believe me, I've done it all. Either way, I'm not getting to a solution. Hope I get some help here..
So Here is the thing.
I'm working on this programme and I want to restrict a user from Submitting the Answers more than once.
Here's my code below, Kindly Help
Note:- This code Produces an error (Http://Tinypic.com/r/rbi4u9/8)
Imports System.Data.OleDb
Imports System.IO
Public Class QSheet
Private Sub QSheet_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
FrmMain.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'----------------------------------------------------------------------
'-------------------------------------------------------------------
Try
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\pant.16\Desktop\Projects\Microsoft - MSV\Microsoft - MSV\bin\Debug\MSVDB.accdb")
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
''
''____________________________________________
''
If MsgBox("Confirm Submit?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question) = MsgBoxResult.Yes Then
Dim cmd1 As New OleDb.OleDbCommand("INSERT INTO [" + Label11.Text + "](EmpID,Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10) values([@EmpID],[@ans1],[@ans2],[@ans3],[@ans4],[@ans5],[@ans6],[@ans7],[@ans8],[@ans9],[@ans10]) WHERE NOT EXISTS (SELECT EmpID FROM [" + Label11.Text + "] WHERE EmpID = [" + Login.txtEmpID.Text + "])", cn)
' EmpID
Dim EmpID As OleDbParameter = New OleDbParameter("@EmpID", OleDbType.VarWChar, 15)
EmpID.Value = Login.txtEmpID.Text.ToString()
cmd1.Parameters.Add(EmpID)
'Answer1
Dim ans1 As OleDbParameter = New OleDbParameter("@ans1", OleDbType.VarWChar, 50)
ans1.Value = ComboBox1.Text.ToString()
cmd1.Parameters.Add(ans1)
'Answer2
Dim ans2 As OleDbParameter = New OleDbParameter("@ans2", OleDbType.VarWChar, 50)
ans2.Value = ComboBox2.Text.ToString()
cmd1.Parameters.Add(ans2)
'Answer3
Dim ans3 As OleDbParameter = New OleDbParameter("@ans3", OleDbType.VarWChar, 50)
ans3.Value = ComboBox3.Text.ToString()
cmd1.Parameters.Add(ans3)
'Answer4
Dim ans4 As OleDbParameter = New OleDbParameter("@ans4", OleDbType.VarWChar, 50)
ans4.Value = ComboBox4.Text.ToString()
cmd1.Parameters.Add(ans4)
'Answer5
Dim ans5 As OleDbParameter = New OleDbParameter("@ans5", OleDbType.VarWChar, 50)
ans5.Value = ComboBox5.Text.ToString()
cmd1.Parameters.Add(ans5)
'Answer6
Dim ans6 As OleDbParameter = New OleDbParameter("@ans6", OleDbType.VarWChar, 50)
ans6.Value = ComboBox6.Text.ToString()
cmd1.Parameters.Add(ans6)
'Answer7
Dim ans7 As OleDbParameter = New OleDbParameter("@ans7", OleDbType.VarWChar, 50)
ans7.Value = ComboBox7.Text.ToString()
cmd1.Parameters.Add(ans7)
'Answer8
Dim ans8 As OleDbParameter = New OleDbParameter("@ans8", OleDbType.VarWChar, 50)
ans8.Value = ComboBox8.Text.ToString()
cmd1.Parameters.Add(ans8)
'Answer9
Dim ans9 As OleDbParameter = New OleDbParameter("@ans9", OleDbType.VarWChar, 50)
ans9.Value = ComboBox9.Text.ToString()
cmd1.Parameters.Add(ans9)
'Answer10
Dim ans10 As OleDbParameter = New OleDbParameter("@ans10", OleDbType.VarWChar, 50)
ans10.Value = ComboBox10.Text.ToString()
cmd1.Parameters.Add(ans10)
If cmd1.ExecuteNonQuery() Then
cn.Close()
MsgBox("Your Answers Have Been Submitted Successfully", MsgBoxStyle.Information, "Information Saved")
Me.Close()
Else
MsgBox("Your Answers Couldn't be Submitted", MsgBoxStyle.Critical, "Save Failed")
Return
End If
End If
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "Error")
Exit Sub
End Try
End Sub
Private Sub QSheet_Load(sender As Object, e As EventArgs) Handles Me.Load
Label11.Text = Login.inval.Text
End Sub
Sub comboboxdefaultvalues()
ComboBox1.Text = "Select an Option"
ComboBox2.Text = "Select an Option"
ComboBox3.Text = "Select an Option"
ComboBox4.Text = "Select an Option"
ComboBox5.Text = "Select an Option"
ComboBox6.Text = "Select an Option"
ComboBox7.Text = "Select an Option"
ComboBox8.Text = "Select an Option"
ComboBox9.Text = "Select an Option"
ComboBox10.Text = "Select an Option"
End Sub
End Class
Please somebody help me get to a final resolution.