【发布时间】:2017-03-12 03:14:13
【问题描述】:
我无法将问题(txtQuestion.Text)添加到 dataGridView 但如果您添加相同的问题,它会起作用并显示 MessageBox.Show(“您不能输入相同的问题。”)。添加数据是我唯一的问题。
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
【问题讨论】:
-
请记住将解决您问题的答案标记为已接受。
标签: database vb.net datagridview datagrid