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 6902813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:50:44+00:00 2026-05-27T07:50:44+00:00

Given a DataView that contains multiple rows, I want to extract a row based

  • 0

Given a DataView that contains multiple rows, I want to extract a row based on the following criteria;

  • If a row starts with a certain string and ends with a certain string, then choose that row above all others
  • If no rows meet the first criteria, then just look for a row that start with the certain string
  • If we can’t match any of the above, default to null.

My quick attempt simply returns the first row that meets any criteria (excuse me if the VB syntax isn’t right, I’m not that familiar with it);

  Dim result = (From row In dv.Table.Rows() _
                Where (GetString(row, "id").StartsWith(Me.ID.Substring(0, 3), StringComparison.OrdinalIgnoreCase) AndAlso _
                GetString(row, "id").EndsWith(Me.ID.Substring(Me.RegisteredID.Length - 2, 2), StringComparison.OrdinalIgnoreCase)) OrElse _
                GetString(row, "id").StartsWith(Me.ID.Substring(0, 3), StringComparison.OrdinalIgnoreCase) _
                Select row).FirstOrDefault()

Edit: I meant to add that something like https://stackoverflow.com/a/443055/685760 looks promising, but I don’t think it will work in my situation. Feel free to correct me if I’m wrong.

  • 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-27T07:50:44+00:00Added an answer on May 27, 2026 at 7:50 am

    It would be difficult, if not impossible, to express that kind of algorithm in a query. A query will only judge each row independantly from the others.
    You need to have the resultset of the first criteria before you can check for the second…

    In my opinion you need to do three separate queries (which might just be ending up executing only the first one if it returns any result, since at that point you met your first criteria and do not need to check for other results).
    The other way would be, I guess, through some kind of ranking of the data, but you might end up with something less clear AND less performant.

    In any case, your code will be a hundred times more readable for common mortals, even if there was a way to express your needs in a query. There is such a thing as overuse of Linq 😉

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

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given the following string: s = 'abcdefg*' How can I match it or any
Given the date, 2009/04/30, in one of the rows I want to retrieve all
Given long long int x, y; , I want a function that can compare
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given the following : // get the list of the players , in order
Given this: $ids = ''; I just realized that this: $single = $ids ==
Given a storyboard-based application, how can any one view controller invoke the methods of
I'm stumbling on this data converter stuff, especially with relation to multiple rows and
Given following Table select rv, mv, datetime, rawv from mytable where datetime > '2012-01-30';

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.