Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
896 B
1
Indexable
Never
// Assuming advertisingDT and advertisingExcel are available

foreach (DataRow row in advertisingDT.Rows)
{
    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
    ListItem newItem = targetList.AddItem(itemCreateInfo);

    foreach (DataRow mappingRow in advertisingExcel.Rows)
    {
        string databaseColumn = mappingRow["DatabaseColumn"].ToString();
        string sharePointColumn = mappingRow["SharePointColumn"].ToString();

        if (advertisingDT.Columns.Contains(databaseColumn))
        {
            // Check if the column exists in advertisingDT
            object columnValue = row[databaseColumn];
            newItem[sharePointColumn] = columnValue;
        }
        else
        {
            Console.WriteLine($"Column '{databaseColumn}' not found in advertisingDT.");
        }
    }

    newItem.Update();
}

devspContext.ExecuteQuery();
Leave a Comment