Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
1
Indexable
Never
foreach (DataRow ad in advertisingExcel.Rows)
{
    // Assuming these are the correct column names in your SharePoint list
    string databaseColumnName = ad["DatabaseColumn"].ToString();
    string sharepointColumnName = ad["SharePointColumn"].ToString();

    if (advertisingDT.Columns.Contains(databaseColumnName))
    {
        foreach (DataRow dr in advertisingDT.Rows)
        {
            // Check if the value in the DataTable is null or empty
            object valueFromDataTable = dr[databaseColumnName];
            string finalValue = (valueFromDataTable == null || string.IsNullOrEmpty(valueFromDataTable.ToString()))
                ? $"{dr["OrganixationFirstName"]}{dr["OrganizationLastName"]}"
                : valueFromDataTable.ToString();

            Console.WriteLine($"Database Column: {databaseColumnName}, SharePoint Column: {sharepointColumnName}, Value: {finalValue}");

            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem newItem = targetList.AddItem(itemCreateInfo);

            newItem[sharepointColumnName] = finalValue;
            newItem.Update();
        }
    }
    else
    {
        Console.WriteLine($"Column {databaseColumnName} not found in DataTable.");
    }
}
Leave a Comment