Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6781595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:38:34+00:00 2026-05-26T16:38:34+00:00

I’m trying to search a DataTable for a row I know exists. // This

  • 0

I’m trying to search a DataTable for a row I know exists.

// This is the row my search should find
DataRow goal = dtLkupCat.Rows[6];

// This finds the row correctly
string srchexpr = String.Format("sport = '{0}' and catcode = '{1}' and type = '{2}' and [parent] = '{3}' and code = '{4}'", goal["sport"], goal["catcode"], goal["type"], goal["parent"], goal["code"]);
DataRow[] test = dtLkupCat.Select(srchexpr);

// But if I set a PK and search for the values I know to be correct, it returns null
dtLkupCat.PrimaryKey = new DataColumn[] { dtLkupCat.Columns["sport"],
                                          dtLkupCat.Columns["catcode"],
                                          dtLkupCat.Columns["type"],
                                          dtLkupCat.Columns["parent"],
                                          dtLkupCat.Columns["code"]};
DataRow lkup = dtLkupCat.Rows.Find(new object[] { goal["sport"], goal["catcode"], goal["type"], goal["parent"], goal["code"] });

There’s nothing special about the columns/values it’s searching. They’re all valid strings, and none are null/DBNull. What am I missing here? I can use the Select() as a workaround, obviously, but would like to know why Find() won’t work.

UPDATE: I’ve posted the xml from a subset of my lookup table if anyone wants to give this a try. You can download it from: http://www.flantech.net/files/lkup_cat2.zip

Then try running this code. It’s strange, it will find the row using different combinations of four columns, but never with all five columns.

DataTable dtLkupCat = new DataTable("lkup_cat");
dtLkupCat.ReadXml(@"lkup_cat2.xml");

// This is the row my search should find
DataRow goal = dtLkupCat.Rows[0];

// This is how I need to do the search, but it doesn't find the row
dtLkupCat.PrimaryKey = new DataColumn[] { dtLkupCat.Columns["sport"],
                                          dtLkupCat.Columns["catcode"],
                                          dtLkupCat.Columns["type"],
                                          dtLkupCat.Columns["parent"],
                                          dtLkupCat.Columns["code"]};
DataRow found = dtLkupCat.Rows.Find(new object[] { goal["sport"], goal["catcode"], goal["type"], goal["parent"], goal["code"] });
Debug.WriteLine((found == null ? "not " : "") + "found");

// Here I remove the "sport" column from the PK, and it finds the row
dtLkupCat.PrimaryKey = new DataColumn[] { dtLkupCat.Columns["catcode"],
                                          dtLkupCat.Columns["type"],
                                          dtLkupCat.Columns["parent"],
                                          dtLkupCat.Columns["code"]};
found = dtLkupCat.Rows.Find(new object[] { goal["catcode"], goal["type"], goal["parent"], goal["code"] });
Debug.WriteLine((found == null ? "not " : "") + "found");

// Here I remove the "catcode" column from the PK, and it finds the row
dtLkupCat.PrimaryKey = new DataColumn[] { dtLkupCat.Columns["sport"],
                                          dtLkupCat.Columns["type"],
                                          dtLkupCat.Columns["parent"],
                                          dtLkupCat.Columns["code"]};
found = dtLkupCat.Rows.Find(new object[] { goal["sport"], goal["type"], goal["parent"], goal["code"] });
Debug.WriteLine((found == null ? "not " : "") + "found");

// Here I remove the "type" column from the PK, and it finds the row
dtLkupCat.PrimaryKey = new DataColumn[] { dtLkupCat.Columns["sport"],
                                          dtLkupCat.Columns["catcode"],
                                          dtLkupCat.Columns["parent"],
                                          dtLkupCat.Columns["code"]};
found = dtLkupCat.Rows.Find(new object[] { goal["sport"], goal["catcode"], goal["parent"], goal["code"] });
Debug.WriteLine((found == null ? "not " : "") + "found");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:38:34+00:00Added an answer on May 26, 2026 at 4:38 pm

    Per MS:

    Thanks for reporting this issue. We investigated the problem and it is a bug in our code. As fixing the issue will cause a breaking change, we will need to carefully evaluate when and how to fix this issue so that it will cause minimum negative impact on our existing customers. We already have an existing Connect bug which tracks this problem (http://connect.microsoft.com/VisualStudio/feedback/details/491319/dataset-designer-generates-invalid-datarelations). I will resolve this bug as “duplicate” of Connect bug #491319, but we will keep you updated as we make progress.
    Meantime as a workaround, you either can set PK to null before setting the primary key, make the Constraint on the XML to match the order of the new PK on code, or cleanup Constraints and relations before setting the PK and perform Find.

    https://connect.microsoft.com/VisualStudio/feedback/details/694803/datatable-rows-find-fails-to-locate-row

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.