PC Review


Reply
Thread Tools Rate Thread

How to find an index to the DataView whewn I sort on Country

 
 
Tony
Guest
Posts: n/a
 
      30th Dec 2011
This is just an example for leaning why not things work as I expect.
I want to find the index entry in the DataView collection to the ContactName
= Aria Cruz when we sort on Country ?

I could do the following.

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
string strSQL = "select CustomerID, CompanyName,ContactName, Phone,
City, Country from Customers";
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

DataTable tbl = new DataTable("Customers");
da.Fill(tbl);

DataView dv = new DataView(tbl);

dv.Sort = "ContactName";
int indexToContactname = dv.Find("Aria Cruz");
DataRow rowToFind = dv[indexToContactname ].Row();

DataView vueByCountry = new DataView(tbl);
datavjuCountry.Sort = "Country";
string strCountry = rowToFind["Country"].ToString();

foreach(DataRowView myRowView in vueByCountry)
{
if (myRowView .Row == rowToFind)
{
...
break;

}
}
}

I have made another attemt to find a solution to find the index entry in the
DataView collection to the ContactName = Aria Cruz when we sort on Country
but that doen not work as expected and I hope somebody can explain why.
Here is my attempt to this solution
I first find the DataRowView object called findme in the DataView when I
sort on ContactName.
Then I create a second DataView that I sort on Country. Now I use the
IndexOf method in the interface IList to locate the object findme in the new
DateView datavjuCountry but this will not give a match and I can't
understand why ?

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionString);
string strSQL = "select CustomerID, CompanyName,ContactName, Phone,
City, Country from Customers";
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);

DataTable tbl = new DataTable("Customers");
da.Fill(tbl);

DataView dv = new DataView(tbl);

dv.Sort = "ContactName";
int index = dv.Find("Aria Cruz");
DataRowView findme = dv[index];

DataView datavjuCountry = new DataView(tbl);
datavjuCountry.Sort = "Country";


int slask = ((IList)datavjuCountry).IndexOf(findme);
}




//Tony


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typing 'Up Country' ends up as Up Country' ? Martin @nohere.net Microsoft Excel Misc 4 8th May 2009 06:32 PM
Strongly typed dataset, sorted by dataview, how to get dataset's row index from dataview? Thomas H Microsoft ADO .NET 2 9th Mar 2006 04:04 PM
Onchange of dropdownlist say "country" loaded,it must load all "states" for that country in another drop downlist. S.Guhananth Microsoft ASP .NET 1 30th Apr 2005 01:01 PM
country setting doesn't match actual default country =?Utf-8?B?YXhlbGxvZGk=?= Windows XP Help 5 14th Nov 2004 10:50 AM
Matching Address Country with Phone Number Country Outlook 2003 Alexander Schek Microsoft Outlook 0 29th Oct 2003 05:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.