Groups | Blog | Home
all groups > vb.net > september 2004 >

vb.net : Checking records of database before inserting in VB.NET


Mamatha
9/29/2004 9:38:20 PM
Hi

I want to insert data into the database from VB.NET,before
inserting i want to check those records for eleminate of
duplication.
I tried with thte dataset but i didn't get the correct
output.If any one suggest me thanks in advance.


Cor Ligthert
9/30/2004 10:08:19 AM
Mamatha,

There is no build in method for that, however you can try this snippet I
once made which is in fact a generic one.

\\\Needs a datatabel and a grid on a form.
Me.DataGrid1.DataSource = distinct(dt, "MyDistinctElement")
End Sub
Public Function distinct(ByVal dt As DataTable, _
ByVal dist As String) As DataTable
Dim dtclone As DataTable = dt.Clone
Dim dv As New DataView(dt)
dv.Sort = dist
Dim myselold As String = ""
For i As Integer = 0 To dv.Count - 1
If myselold <> dv(i)(dist).ToString Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To drn.ItemArray.Length - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)(dist).ToString
dtclone.Rows.Add(drn)
End If
Next
Return dtclone
End Function
///
I hope this helps a little bit?

Cor
"Mamatha" <mail2mamathak@yahoo.com>

AddThis Social Bookmark Button