[C# net4] Insert in DB the values of xslt file
I need insert in DB the values of xslt file and I tried this code.
The insert in DB is executed but for only first row of xsl file.
I would greatly appreciate any help you can give me in working this problem, thank you.
code behind file:
XmlTextReader reader = new XmlTextReader(stream);
reader.XmlResolver = null;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
xmlRSS.XPathNavigator = doc.CreateNavigator();
XmlNodeList dataNodes = doc.SelectNodes("rss");
OdbcCommand command;
OdbcDataAdapter adpter = new OdbcDataAdapter();
foreach (XmlNode node in dataNodes)
{
string title = node.SelectSingleNode("//title").InnerText;
string description = node.SelectSingleNode("//description").InnerText;
string pubDate = node.SelectSingleNode("//pubDate").InnerText;
string sql = "insert into Product (title, description, pubdate) values ('" + title.ToString() + "', '" + description.ToString() + "', STR_TO_DATE('" + pubDate.ToString() + "', '%a, %d %b %Y %H:%i:%s GMT'));";
connection.Open();
command = new OdbcCommand(sql, connection);
adpter.InsertCommand = command;
adpter.InsertCommand.ExecuteNonQuery();
connection.Close();
}
xslt file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="title"/>
<xsl:template match="rss">
<xsl:for-each select="channel/item">
<br>
<strong>
<a href="{link}" target="_main">
<xsl:value-of select="title"/>
</a>
</strong>
<br></br>
<xsl:value-of select="description" disable-output-escaping="yes"/>
</br>
<br></br>
<xsl:value-of select="pubDate"/>
<br></br>
</xsl:for-each>
</xsl:template>
<xsl:template match="description">
<br>
<xsl:value-of select="."/>
</br>
</xsl:template>
</xsl:stylesheet>