0
我有一個SharePoint列表,其中有100個項目,我最初從SQL中的一個表中填充。現在,我想更新那些已更改的項目並添加新項目。如何根據列表中的列更新項目?任何幫助深表感謝。SharePoint - 更新列表項如果ID存在其他AddItem
這是我已初步添加的項目:
Microsoft.SharePoint.Client.List oList_Donors = context.Web.Lists.GetByTitle("XYZ");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
using (OdbcConnection connection = new OdbcConnection())
{
connection.ConnectionString = "dsn=abc;uid=efg;pwd=hij;DataSource=klm";
connection.ConnectionTimeout = 100;
connection.Open();
OdbcCommand command_abc = new OdbcCommand("Select * From vw_SP_abc_efg", connection);
try
{
using (OdbcDataReader reader = command_abc.ExecuteReader())
{
while (reader.Read())
{
var obj0 = reader.GetValue(48);
var obj1 = reader.GetValue(0);
var obj2 = reader.GetValue(33);
var obj3 = reader.GetValue(47);
var obj4 = reader.GetValue(42);
var obj5 = reader.GetValue(42);
ListItem oListItem_abc = oList_abc.AddItem(itemCreateInfo);
oListItem_abc["Title"] = (obj0 == null || obj0.Equals(DBNull.Value)) ? "" : reader.GetString(48).ToString();
oListItem_abc["abc_x0020_ID"] = (obj1 == null || obj1.Equals(DBNull.Value)) ? "" : reader.GetString(0).ToString();
oListItem_abc["Excluded_x0020_By"] = (obj2 == null || obj2.Equals(DBNull.Value)) ? "" : reader.GetString(33).ToString();
oListItem_abc["Excluded_x0020_On"] = (obj3 == null || obj3.Equals(DBNull.Value)) ? "" : reader.GetDateTime(47).ToString("MM/dd/yyyy");
oListItem_abc["Reason"] = (obj4 == null || obj4.Equals(DBNull.Value)) ? "" : reader.GetString(42).Substring(50, reader.GetString(42).ToString().Length - 50);
oListItem_abc["Publish"] = (obj5 == null || obj5.Equals(DBNull.Value)) ? "" : reader.GetString(42).Substring(50, reader.GetString(42).ToString().Length - 50);
oListItem_abc.Update();
context.ExecuteQuery();
}
}
}
catch (Exception exception)
{
Console.WriteLine("The Error is:" + exception);
Console.ReadLine();
}
}
您是否擁有該項目的共享點ID? –
我的ID不是SharePoint ID。我也可以激活sharepoint id – SharePointDummy
如果你有一個主鍵,你可以映射兩者只需做一個caml查詢來獲取項目並更新它 –