?
Solved

VB.net 2.0 - Dynamic TableAdapater

Posted on 2013-06-20
6
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 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