|
-
Jul 7th, 2017, 06:44 PM
#1
Thread Starter
Lively Member
[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
-
Jul 8th, 2017, 07:08 AM
#2
Hyperactive Member
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
Last edited by AceDuk; Jul 8th, 2017 at 07:23 AM.
Reason: Improved
Please Mark your Thread "Resolved", if the problem is solved & Rate those who have helped you 
-
Jul 10th, 2017, 02:40 PM
#3
Thread Starter
Lively Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|