[RESOLVED] How to validate data on datagridview to prevent duplicate
for example i have "NID" as textbox and datagrid with @NID field.
i want save NID with Value "N001" to @NID on datagrid.
how to prevent duplicate when i save NID with value "N001" to datagrid.
I trying like this but error :
Code:
private sub save()
dim dgv as datagridview1
if dgv.CurrentRow.Cells(0).value = NID.text then
msgbox("Data duplicate")
else
dgv.rows.insert(.NewRowIndex, NID.text)
end if
end sub
help me
thanks
Re: How to validate data on datagridview to prevent duplicate
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Exists As Boolean = False
For Each item As DataGridViewRow In DataGridView1.Rows
If item.Cells(0).Value = NID.Text Then
Exists = True
End If
Next
If DataGridView1.Rows.Count > 0 AndAlso Exists = True Then
MsgBox("Data duplicate")
Exit Sub
Else
DataGridView1.Rows.Insert(DataGridView1.NewRowIndex, NID.Text)
End If
End Sub
Re: How to validate data on datagridview to prevent duplicate
Problem solved ...
I used this code -->
Code:
For i As Integer = 0 To dataspdibeli.Rows.Count - 1
If Not IsDBNull(dataspdibeli.Rows(i).Cells("NID_SP").Value) AndAlso dataspdibeli.Rows(i).Cells("NID_SP").Value = spnid.Text Then
thanks <-_->
#junior_programmer