Solved

VB.net 2.0 - Dynamic TableAdapater

Posted on 2013-06-20
6
172 Views
Last Modified: 2013-06-25
OK, Here is my situation!

I added a NEW DataSet call "Temp" I added a NEW DataTable called "Temp_DataTable" using and added one column.

Now when I right click I'm unable to add a Table Adapter to write a query to Fill/GetData from my NEW DataTable?

What I'm trying to do is I'm currently reading a Text File into a DataTable and once all the records have been loaded I want to run a SQL Statement on that DataTable to weed out the duplicate records, so how can I accomplish this?

Thanks,
Mark
0
Comment
Question by:smithmrk
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39268706
>to weed out the duplicate records

Use DataTable.DefaultView.ToTable method

http://msdn.microsoft.com/en-us/library/h2b6ehaa.aspx
0
 

Author Comment

by:smithmrk
ID: 39271387
OK, Thanks CodeCruiser!
That is some pretty good stuff, but I'm curious if there is a way I can do it using either the Wizard or SQL Statements.  See example of a SQL Statement I'm currently using in the Wizard on a thick database and would like to do something similar to a DataTable.

Currently on some other programs I write out the records to a database and use a SQL Statement to Group to weed out the duplicate records...in the example I gave you I want ALL the duplicates so I can write out a log showing all the duplicate records to provide to the group.

Thanks,
Mark
TableAdapterSQL.jpg
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39271533
So you want to find out all the duplicate entries?

One way is to use LINQ

Dim duplicates = dt.AsEnumerable().GroupBy(Function(r) New With { _
	Key .a = r(0), _
	Key .b = r(1) _
}).Where(Function(gr) gr.Count() > 1)
lbMsg.Text = "Duplicate Record found for Rows: " & [String].Join(", ", duplicates.[Select](Function(dupl) dupl.Key))

Open in new window



http://codenicely.blogspot.co.uk/2012/01/finding-duplicate-rows-in-datatable.html

http://stackoverflow.com/questions/8939516/how-to-find-duplicate-record-using-linq-from-datatable
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:smithmrk
ID: 39271581
OK, but remember my subject line...I'm using Visual Studio 2005 (.net 2.0) I didn't think I could use LINQ in this version?

Thanks,
Mark
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39272218
Yup missed that. You will need to do some manual work in that case.

1) Export to another datatable with distinct option
2) Loop through this new datatable and set RowFilter on original datatable
3) Check the count of defaultview after row filter and if its more than 1 then you got duplicates.
0
 

Author Closing Comment

by:smithmrk
ID: 39274873
OK...I guess I need to upgrade, because I hate manual work!
I appreicate your suggustions and I'll see what I can do in the mean time to report out my duplicate records...I was hoping there was an easier way that I was missing, but I guess not.

Thanks,
Mark
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 (3.5 Framework) Remove all items from List 3 32
How to open form using item in Listbox. 8 23
Help with error in Query 2 31
Passing data between Forms 3 20
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question