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

  • Home
  • SEARCH
  • 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 4063070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:40:45+00:00 2026-05-20T15:40:45+00:00

I might be approaching this problem completely wrong, but I’m still a bit new

  • 0

I might be approaching this problem completely wrong, but I’m still a bit new to SP development and it’s late in the evening.

EDIT: Yup, I’m thinking about this wrong. I just remembered that the SPListCollection is tied to the DB, and if I were to add records it won’t work. I’m going to try a cross list query instead.

I have two SP lists that I need to query off one, get a list of items, then using those items ID’s query another list to get it’s “children” each parent can have multiple children.

I can get that to work fine, the kicker is I need to build a SPListItemCollection for use in other parts of the code. I’m trying to retrofit some stuff to work with this new look up process, and it’s all based on SPListItemCollections. Here’s a code snippet:

foreach (SPListItem i in NAICParents)
                {


                    //query child slides
                    SPQuery qChildren = new SPQuery();
                    SPFieldLookupValue tmp = new SPFieldLookupValue(i.ID, i.Title);
                    qChildren.Query = "<Where><Eq><FieldRef Name=\"paNAICParent\" /><Value Type=\"Lookup\">" + tmp.ToString().Substring(tmp.ToString().IndexOf('#') + 1) + "</Value></Eq></Where>";
                    target = _web.Lists["paNAICUpdateSlides"];
                    SPListItemCollection children = target.GetItems(qChildren);

                    SPListItem temp = null;
                    foreach (SPListItem l in children)
                    {
                        temp =itmAll2.Add();
                        temp = l;
                        temp.Update();


                    }
                }

It dies at the temp = itmAll2.add() . I get a null reference error. Which makes sense, because I never instantiated the SPListItemCollection, but I can’t get the code to let me instantiate that to blank.

Can I copy the structure of a list to instantiate a blank list? Or something like that?

Thanks,

  • 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-20T15:40:45+00:00Added an answer on May 20, 2026 at 3:40 pm

    I would not recommend trying to reuse an SPListItemCollection in your code. This can result in SPWeb objects being reopened behind the scenes.

    Instead, I would use SPListItemCollection.GetDataTable to get a DataTable that will hold your in memory object which you can then reuse across your code. Alternatively you could create Bean objects that would correspond to each item in the list.

    Then, you can add or remove items to your in-memory objects without opening more database connections.

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

Sidebar

Related Questions

I might be a little late on this but I was going through how
This might be a silly question, but: Suppose an expression depends only on literals,
This might be a very simple thing in jquery but I am not able
This might be tough to read, but essential is does this over and over
This might be a little subjective, but I'd like to get your input on
this might be quite a newbie question, but i need to process a certain
What are the steps that you follow when approaching a problem statement, which needs
Might be a dumb question but I need a confirmation regardless. In ASP.NET, if
I might be mis-understanding here but from my understanding a markdown editor strips out
I have a simple report sending framework that basically does the following things: It

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.