我想防止使用以下代码在数据库中输入重复滚动,但这没有帮助,并且还建议如何在 gridview 中防止这种情况。
If txtRollNo.Text.Trim = "" Then
ErrorProvider1.SetError(txtRollNo, "Roll Number is required")
Errorcheck = False
ElseIf varDuplicate = True Then
MessageBox.Show("Duplicate values are not allowed")
Else
ErrorProvider1.SetError(txtRollNo, "")
End If
Private Function Duplicate() As Boolean
Duplicate = True
duplicatedata = "Select Count(RollNo) from KaiyumVbStudent where RollNO = &txtRollNo.Text.Trim"
con = New SqlConnection(constring)
cmd = New SqlCommand(duplicatedata, con)
con.Open()
Dim mcount As Integer = cmd.ExecuteScalar
If mcount > 0 Then
Duplicate = True
Else
Duplicate = False
End If
End Function