With sincere help from experts in this wonderful forum, I have been able to parsed my xml returned by a SharePoint list to get the desired list items into C# Lists.
XDocument xdoc = XDocument.Parse(activeItemData.InnerXml);
XNamespace z = "#RowsetSchema";
List<int> listID = (from row in xdoc.Descendants(z + "row")
select (int)row.Attribute("ows_ID")).ToList();
List<string> listTitle = (from row in xdoc.Descendants(z + "row")
select (string)row.Attribute("ows_LinkTitle")).ToList();
I have created a SQL table and I want to insert values in my table using Lists listID and listTitle as parameters
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(MyconnectionString);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT TechOpsProjectTracker (ID, [Project Name]) VALUES (@ID, @ProjectName)";
//What I want to do:
//1. @ID should get the values from the List listID: List<int> listID = (from row in xdoc.Descendants(z + "row") select (int)row.Attribute("ows_ID")).ToList();
//2. @ProjectName should get the values from the List listTitle: List<string> listTitle = (from row in xdoc.Descendants(z + "row") select (string)row.Attribute("ows_LinkTitle")).ToList();
//3. so each new record inserted in the table has ID and its corresponding Project Name. Something like this
/* ID Project Name
360 GEI Survey data to Sharepoint
378 Create back end and environment to support User demographic reporting
*/
There might be some other possibly easier ways to accomplish my job. Please let me know. TIA.