Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
1
Indexable
Never
// 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))
{
    for (int i = 0; i < advertisingExcel.Rows.Count; i++)
    {
        DataRow excelRow = advertisingExcel.Rows[i];

        if (i < advertisingDT.Rows.Count)
        {
            DataRow dr = advertisingDT.Rows[i];

            // 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