By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,835 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

Checking records of database before inserting in VB.NET

P: n/a
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.
Mamatha
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <ma***********@yahoo.com>
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.