Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.net 2.0 - Dynamic TableAdapater

Posted on 2013-06-20
6
Medium Priority
?
177 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

618 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