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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:45:51+00:00 2026-05-27T19:45:51+00:00

While looping through records in one list, I want to find a corresponding line

  • 0

While looping through records in one list, I want to find a corresponding line in another list containing more information for that item. I am getting a conversion error when trying to use LINQ to get this information from the first list.

public class qtyAvail
{
    public string itemNumber;
    public string qtyAv;
}

public class variance
{
    public string siteID;
    public string itemNumber;
    public string varQty;
}

    public void saveVariance(Context context)
    {
        var settings = PreferenceManager.GetDefaultSharedPreferences(context);
        var siteID = settings.GetString("siteID", null);
        updateInv(siteID);

        var inst = new InventoryApp();
        List<variance> ilist = new List<variance>();
        List<qtyAvail> avail = new List<qtyAvail>();
        SqliteDataReader dr;

        var connection = new SqliteConnection("Data Source=" + dbPath);
        connection.Open();
        var c = connection.CreateCommand();
        c.CommandText = "Select ItemNmbr, OnHnd - Alloc From PartInfo";
        dr = c.ExecuteReader();

        while (dr.Read())
        {
            qtyAvail qa = new qtyAvail();
            qa.itemNumber = dr[0].ToString();
            qa.qtyAv = dr[1].ToString();
            avail.Add(qa);
        }
        dr.Close();
        c.CommandText = "Select * From Items";
        dr = c.ExecuteReader();

        while (dr.Read())
        {
            variance v = new variance();
            v.siteID = siteID;
            v.itemNumber = dr[0].ToString();
            v.varQty = from q in avail where q.itemNumber == dr[1].ToString() select q.qtyAv;
            ilist.Add(v);
        }
        dr.Close();
        connection.Close();

        inst.saveVariance(siteID, ilist.ToArray());
    }

When I build the solution I get

Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable<string>‘ to ‘string‘

On the line where I use LINQ to assign v.varQty. I am sure there is some simple thing I am missing but just can’t find the right cast, conversion, etc. I also realize that I could easily just perform the select on the Sqlite table to get the information rather than using lists, but I am trying to figure all this LINQ stuff out so I want to get it to work this way too.

  • 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-27T19:45:51+00:00Added an answer on May 27, 2026 at 7:45 pm
    v.varQty = from q in avail where q.itemNumber == dr[1].ToString() select q.qtyAv;
    

    Your query returns an IEnumerable<string> and not a single string -since varQty is a string use FirstOrDefault() here:

    v.varQty = (from q in avail where q.itemNumber == dr[1].ToString() select q.qtyAv).FirstOrDefault();
    

    Or shorter in dot notation:

    v.varQty = avail.Where(q => q.itemNumber == dr[1].ToString()).FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While looping through a Dataset which code snippet should I use, should I go
If I am looping through an ADO.Recordset (with while not recordSet.EOF ), is there
I'm looping through each line of a series of CURL returned http headers, trying
A query that is used to loop through 17 millions records to remove duplicates
How can I get the next record from a collection while looping through a
I'm working through a CSV importing approach that I want to teach to other
While looking at a micro-optimization question that I asked yesterday ( here ), I
I am trying to using a SQL data reader to move records from one
my application shows contact information (from approx. 2000 contact records with various detail information
i will be having a Database with more than 8 hundred billion records, i

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.