Solved

VB.net 2.0 - Dynamic TableAdapater

Posted on 2013-06-20
6
166 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now