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

Checking records of database before inserting in VB.NET

P: n/a

I want to insert data into the database from VB.NET,before
inserting i want to check those records for eleminate of
I tried with thte dataset but i didn't get the correct
output.If any one suggest me thanks in advance.
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

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)
myselold = dv(i)(dist).ToString
End If
Return dtclone
End Function
I hope this helps a little bit?

"Mamatha" <ma***********>
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.