Solved

VB.net 2.0 - Dynamic TableAdapater

Posted on 2013-06-20
6
171 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

770 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