I can't add question(txtQuestion.Text) to the dataGridView but if you add the same question it works and shows MessageBox.Show("You can't enter the same question."). Adding data is my only problem.
Dim qID As String
rnd.Next(0, 99999)
For Each row As DataGridViewRow In UsersDBDataGridView.Rows
If txtQuestion.Text = row.Cells(1).Value.ToString Then '<-- NullReferenceException was unahandled.
MessageBox.Show("You cant enter the same Question.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
valid = True
Exit For
Else
valid = False
End If
Next
If cbxDifficulty.Text = "Easy" Then
diff = "E"
diffValue = 5
ElseIf cbxDifficulty.Text = "Average" Then
diff = "A"
diffValue = 10
ElseIf cbxDifficulty.Text = "Difficult" Then
diff = "D"
diffValue = 20
End If
qID = diff & "-" & Date.Now.Date.ToString("ddMMMyyyy").ToUpper & "-" & rnd.ToString("00000")
If valid = False Then
Me.UsersDBTableAdapter.Add(qID, txtQuestion.Text, txtAnswer.Text, diffValue)
Me.UsersDBTableAdapter.Fill(Me.UsersDBDataSet.UsersDB)
End If