locked
how to convert datatable into splistitemcollection RRS feed

  • Question

  • hi,

    i am new to sharepoint .. 

    can we convert datatable to splistitemcollection .. 

    if possible then how can we do this ...

    or is there any way to to get the SPListItem from the datatable and splistitem.folder using datatable ..

    thankyou..

    Sunday, September 30, 2012 5:45 PM

Answers

  • Hi Daniel,

    We can covert SPListItemCollection to DataTable

    you have to iterate for each row of datatable add it in SPList instance

    SPList prjCmpList = this.web.Lists["Completed-Project-List"];
    SPListItemCollection prjCmpListItems = prjCmpList.Items;
    SPListItem prjCmpListItem;
    
    foreach(DataRow dr in ds.Table[0]){
    prjCmpListItem = prjCmpListItems.Add();  
    prjCmpListItem["Project_Id"] = dr["Project_Id"]; 
    prjCmpListItem["Title"] = dr["Title"];
    prjCmpListItem["Project_Hours"] = dr["Project_Hours"];
    prjCmpListItem["Project_Type"] = dr["Project_Type"];
    prjCmpListItem.Update();
    }



    VOTE, if you find this as HELPFUL // Manivannan Nagarajan

    Monday, October 1, 2012 4:00 AM
  • Hi,

    I guess you have custom data created somewhere and based on that you wish to add data in list. In that way you will need to go with "Manivanan N" suggestion and creating individual item in list.

    you can check you data table field for folder or item and based on it, you can add in your list.

    hope this will help you. If you need more assistance please tell your particular details, so everybody can help.


    Thanks and Regards, Shailesh B. Davara

    Monday, October 1, 2012 5:56 AM

All replies

  • Hi Daniel,

    We can covert SPListItemCollection to DataTable

    you have to iterate for each row of datatable add it in SPList instance

    SPList prjCmpList = this.web.Lists["Completed-Project-List"];
    SPListItemCollection prjCmpListItems = prjCmpList.Items;
    SPListItem prjCmpListItem;
    
    foreach(DataRow dr in ds.Table[0]){
    prjCmpListItem = prjCmpListItems.Add();  
    prjCmpListItem["Project_Id"] = dr["Project_Id"]; 
    prjCmpListItem["Title"] = dr["Title"];
    prjCmpListItem["Project_Hours"] = dr["Project_Hours"];
    prjCmpListItem["Project_Type"] = dr["Project_Type"];
    prjCmpListItem.Update();
    }



    VOTE, if you find this as HELPFUL // Manivannan Nagarajan

    Monday, October 1, 2012 4:00 AM
  • Hello,

    Can you please provide more details why you want to do the conversion in reverse direction ?


    Hiren Patel | Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

    Monday, October 1, 2012 4:15 AM
  • Hi,

    I guess you have custom data created somewhere and based on that you wish to add data in list. In that way you will need to go with "Manivanan N" suggestion and creating individual item in list.

    you can check you data table field for folder or item and based on it, you can add in your list.

    hope this will help you. If you need more assistance please tell your particular details, so everybody can help.


    Thanks and Regards, Shailesh B. Davara

    Monday, October 1, 2012 5:56 AM