dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberssunny
Rakesh Chaubey
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

Duplicate values are not displaying in proper order


Posted Date: 29 Mar 2012      Posted By:: SivaSaiKrishna     Member Level: Silver    Member Rank: 1438     Points: 5   Responses: 1



I have column(IHno) in a Table, this coloumn is like

Ihno
1
1
2
3
4
4
7
8
9



and 2 textboxes in Windows Application like IhnoFrom(textboxname) and IhnoTo(textboxname)
in these textboxes i want to give input like range from 1 to 10 1(in IhnoFrom Txtbox) to 10 (in IhnoTo Txtbox)

in these range we find and Display MISSING Numbers and DUPLICATE numbers in IHNO column ,in above column Missing nums are 5,6,10. and Duplicate nums are 1,4 in Gridview

Here is my code :

int Start = Convert.ToInt32(txtIhFrm.Text);
int End = Convert.ToInt32(txtIhTo.Text);
//SqlConnection con = new SqlConnection("server=.;integrated security=true;database=DotNetSpider");
DataTable dt = new DataTable();
SqlDataAdapter sqlda = new SqlDataAdapter("SELECT * FROM " + strDbname + "..paid_tran where Batch_no='" + label9.Text.ToString() + "' and Ihno >='" + txtIhFrm.Text.ToString() + "' and Ihno <= '" + txtIhTo.Text.ToString() + "'", cn);
sqlda.Fill(dt);

string Duplicates="";
string Missing ="";
ArrayList AlUniqueValues = new ArrayList();
foreach (DataRow dr in dt.Rows)
{
if (Convert.ToInt32(dr["Ihno"]) >= 2)
{
Duplicates += Convert.ToString(dr["Ihno"]) + ",";
}
AlUniqueValues.Add(Convert.ToString(dr["Ihno"]));
}

for (int i = Start; i <= End; i++)
{
if (!AlUniqueValues.Contains(Convert.ToString(i)))
{
Missing += Convert.ToString(i) + ",";
}
}

MessageBox.Show("Missing Values: " + Missing.TrimEnd(',') + "\nDuplicate Values: " + Duplicates.TrimEnd(','));
}
}

o/p:Missing nos are 12,14 (its correct)
Duplicate nos are 11,11,13,15


it should display only 11 as duplicate value but its displaying complete range of values.









Thanks nd Regards,

A.SivaSaiKrishna.

+91 9703885006.
E-Mail::sivasaikrishna11@gmail.com.




Responses

#664714    Author: ni nj a      Member Level: Gold      Member Rank: 98     Date: 02/Apr/2012   Rating: 2 out of 52 out of 5     Points: 3

hi,

please change your code like below



List<string> missingList = new List<string>();



for (int i = Start; i <= End; i++)
{
if (!AlUniqueValues.Contains(Convert.ToString(i)))
{

if (!missingList.Contains(Convert.ToString(i)))
missingList.Add(Convert.ToString(i));

}
}



-J



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Retrieving Server name by using advapi32.dll in vb.net
Previous : regarding to show result of all subjects of a student in windows application project
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.