Untitled
unknown
plain_text
2 years ago
1.5 kB
6
Indexable
// 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))
{
int rowCount = Math.Min(advertisingExcel.Rows.Count, advertisingDT.Rows.Count);
var recordsToProcess = Enumerable.Range(0, rowCount)
.Select(i => new
{
ExcelRow = advertisingExcel.Rows[i],
DatabaseRow = advertisingDT.Rows[i]
});
foreach (var record in recordsToProcess)
{
DataRow excelRow = record.ExcelRow;
DataRow dr = record.DatabaseRow;
// 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.");
}
Editor is loading...
Leave a Comment