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 column is "OrganizationName" and if its value is null or DBNull.Value
            string finalValue = (databaseColumnName == "OrganizationName" && dr.IsNull(databaseColumnName))
                ? $"{dr["OrganixationFirstName"]}{dr["OrganizationLastName"]}"
                : dr[databaseColumnName].ToString();

            Console.WriteLine($"Database Column: {databaseColumnName}, SharePoint Column: {sharepointColumnName}, Original Value: {dr[databaseColumnName]}, Final 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