I generate this xml file dynamically and the numbers of items vary. I have SQL database table that just has guid id's. I am trying to compare the guid's of each item in the xml file with the guid id's in the database table. I am trying to display the xml items on a page that don't have their guid already in the database. I am using ADO.NET to get the guid id's from database table and I am trying to read the items through linq to xml to display it on a page. I have been successful in reading the items using linq to xml, but I am trying to figure out how I could implement comparing these guid id's to the guid id’s in the database table. Can I accomplish this inside the linq query that I am writing?
The linq query I am using is:
string FilteredXmlPath = Server.MapPath(ConfigurationManager.AppSettings["FilteredPath"]);
XDocument xdoc = XDocument.Load(FilteredXmlPath);
var postlinks = from links in xdoc.Descendants("item")
select new
{
BlogTitle = links.Element("title").Value,
BlogUrl = links.Element("bloglink").Value,
BlogDate = links.Element("pubdate").Value,
BlogGuid = links.Element("guid").Value
};
Could you please suggest me any sample code or tutorials/ links where I can find comparing a value from linq select query (guid id value)to a database value using ADO.NET?
Could you please suggest me any sample code or tutorials/ links where I can find comparing a value from linq select query (guid id value)to a database value using ADO.NET?
Hi:)
If you have the tables with the same structure as well the same size,column number but just with different kinds of data contents……Just use foreach:
//Suppose you've used SqlDataAdapter.Fill method to fill all the data contents into DataTable,now do this:
for(int i=0;i<DataTable1.Rows.Count;++i)
{
for(int c=0;c<DataTable1.Columns.Count;++c)
{
if(DataTable1.Rows[i][c]!=DataTable2.Rows[i][c])
{
//Do what you want here……
}
}
}
smksu
Member
69 Points
34 Posts
Compare database values with a value from xml file
Mar 27, 2012 08:57 PM|LINK
Hello All,
My project has an xml file that has guid as one of the nodes. Below is the structure of my xml file:
<?xml version="1.0" encoding="utf-8"?> <channel> <item> <title>Welcome Back1</title> <bloglink>http://mysite/blog/posting1.aspx</bloglink> <pubdate>Wed, 07 Mar 2012 21:41:26 GMT</pubdate> <guid>3a8063fe-74e8-4421-8e97-af934b70dc8c</guid> </item> <item> <title>Welcome Back2</title> <bloglink>http://mysite/blog/posting2.aspx</bloglink> <pubdate>Wed, 07 Mar 2012 18:12:44 GMT</pubdate> <date>3/7/2012</date> <guid>b9d91c29-8f44-48e7-add1-be2ab3ae6639</guid> </item> <item> <title>Welcome Back3</title> <bloglink>http://mysite/blog/posting3.aspx</bloglink> <pubdate>Wed, 07 Mar 2012 05:09:20 GMT</pubdate> <guid>7b32def1-fb0d-44eb-8cf5-ebf5377faf07</guid> </item> </channel>I generate this xml file dynamically and the numbers of items vary. I have SQL database table that just has guid id's. I am trying to compare the guid's of each item in the xml file with the guid id's in the database table. I am trying to display the xml items on a page that don't have their guid already in the database. I am using ADO.NET to get the guid id's from database table and I am trying to read the items through linq to xml to display it on a page. I have been successful in reading the items using linq to xml, but I am trying to figure out how I could implement comparing these guid id's to the guid id’s in the database table. Can I accomplish this inside the linq query that I am writing?
The linq query I am using is:
string FilteredXmlPath = Server.MapPath(ConfigurationManager.AppSettings["FilteredPath"]); XDocument xdoc = XDocument.Load(FilteredXmlPath); var postlinks = from links in xdoc.Descendants("item") select new { BlogTitle = links.Element("title").Value, BlogUrl = links.Element("bloglink").Value, BlogDate = links.Element("pubdate").Value, BlogGuid = links.Element("guid").Value };Could you please suggest me any sample code or tutorials/ links where I can find comparing a value from linq select query (guid id value)to a database value using ADO.NET?
smksu
Member
69 Points
34 Posts
Re: Compare database values with a value from xml file
Mar 28, 2012 02:44 PM|LINK
Any suggestions?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Compare database values with a value from xml file
Mar 29, 2012 02:06 AM|LINK
Hi:)
If you have the tables with the same structure as well the same size,column number but just with different kinds of data contents……Just use foreach:
//Suppose you've used SqlDataAdapter.Fill method to fill all the data contents into DataTable,now do this: for(int i=0;i<DataTable1.Rows.Count;++i) { for(int c=0;c<DataTable1.Columns.Count;++c) { if(DataTable1.Rows[i][c]!=DataTable2.Rows[i][c]) { //Do what you want here…… } } }