Hi, need help on finding why code won't run. Keep getting code error: No overload for 'DisplayXML' matches delegate 'System.Web.UI.WebControls.SqlDataSourceSelectingEventHandler'
Would appreciate any help......
System pointing to the following code saying its the cause, but don't know how to fix it:
<asp:SqlDataSource
id="srcProducts"
SelectCommand="SELECT * FROM PRODUCT"
ConnectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True"
Runat="server" onselecting="DisplayXML" />
<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
public void btnXML_Create(object sender, EventArgs e)
{
string _conString = srcProducts.ConnectionString;
string strSQL = "SELECT * FROM PRODUCT";
DataSet ds = new DataSet("PRODUCT");
SqlDataAdapter productsSDA = new SqlDataAdapter(strSQL, _conString);
SqlConnection cn = new SqlConnection(strSQL);
productsSDA.Fill(ds, "PRODUCT");
ds.WriteXml(Server.MapPath("~/DOM/xml/movieDb.xml"));
lblResult.Text = "XML File Created";
XmlTextWriter xmlWriter
= new XmlTextWriter(Server.MapPath("~/DOM/xml/updatedPRODUCT.xml"), null);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("PRODUCT");
/*xmlWriter.WriteStartElement("car");
xmlWriter.WriteStartElement("MOVIE_NAME");
xmlWriter.WriteAttributeString("foreign","true");
xmlWriter.WriteString("Lion King");
xmlWriter.WriteEndElement(); */ // end <MOVIE>
xmlWriter.WriteElementString("PRODUCT_NAME", "Lion King");
xmlWriter.WriteElementString("RELEASE_DATE", "15 June 1994");
xmlWriter.WriteElementString("ACTOR", "James Earl Jones, Jonathan Taylor Thomas");
xmlWriter.WriteElementString("DIRECTOR", "Roger Allers, Rob Minkoff");
xmlWriter.WriteElementString("LANGUAGE", "English");
xmlWriter.WriteElementString("GENRE", "family");
xmlWriter.WriteElementString("CATEGORY", "Movie");
xmlWriter.WriteElementString("RATING", "G");
xmlWriter.WriteElementString("DISCOUNT", "10% off");
xmlWriter.WriteElementString("QUANTITY", "20");
xmlWriter.WriteElementString("PRICE", "$5.00");
xmlWriter.WriteElementString("MANUFACTURER", "Walt Disney Pictures");
xmlWriter.WriteElementString("UNTI_WEIGHT", "7.5 ounces");
xmlWriter.WriteElementString("SHORT_DESCRIPTION", "Young lion cub, Simba, is force to choose between loyalty to his individual self and his pride.");
xmlWriter.WriteElementString("LONG_DESCRIPTION", "Young lion cub, Simba, is forced from his pride, afer his father his family is torn apart by a tragedy, which causes his pride to erupt in turmoil until he is forced to choose between loyalty to his individual self and his pride.");
xmlWriter.WriteElementString("KEYWORD_LIST", "lion");
xmlWriter.WriteElementString("IMAGE_SMALL", "~/Images/LionKingsmall.jpg");
xmlWriter.WriteElementString("IMAGE_LARGE", "~/Images/LionKinglarge.jpg");
xmlWriter.WriteEndElement(); // end <PRODUCT>
/*xmlWriter.WriteStartElement("car");
xmlWriter.WriteStartElement("make");
xmlWriter.WriteAttributeString("foreign", "false");
xmlWriter.WriteString("Ford");
xmlWriter.WriteEndElement(); // end <make>
xmlWriter.WriteElementString("model", "F-150");
xmlWriter.WriteElementString("color", "Blue");
xmlWriter.WriteElementString("year", "2000");
xmlWriter.WriteEndElement(); // end <car>
xmlWriter.WriteEndElement(); // end <cars> */
xmlWriter.Flush();
xmlWriter.Close();
lblResult.Text = "XML written successfully!";
}
public void Page_Load(object sender, EventArgs e)
{
XmlTextReader xmlReader = new XmlTextReader(Server.MapPath("~/DOM/xml/article.xml"));
DisplayXML(xmlReader);
xmlReader.Close();
}
public void DisplayXML(XmlTextReader xmlReader)
{
while (xmlReader.Read()) // read() for each node
{
if (xmlReader.NodeType == XmlNodeType.Element)
{
Response.Write("<br>");
Response.Write("<b>Element: </b>" + xmlReader.Name);
if (xmlReader.HasAttributes)
{
Response.Write(" <b>Attributes: </b>");
for (int attIdx = 0; attIdx < xmlReader.AttributeCount; attIdx++)
{
//the Item property retrieves the value for each node's attribute
Response.Write(xmlReader[attIdx]);
if (attIdx < xmlReader.AttributeCount - 1)
{
Response.Write(", ");
}
}
}
}
else if (xmlReader.NodeType == XmlNodeType.Text)
{
Response.Write(" <b>Value: </b>" + xmlReader.Value);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show XML File</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--<asp:SqlDataSource
id="srcProducts"
DataSourceMode="DataReader"
SelectCommand="SELECT * FROM PRODUCT"
ConnectionString="<%$ ConnectionStrings:eBizDatabase %>"
Runat="server" onselecting="DisplayXML" />--%>
<asp:SqlDataSource
id="srcProducts"
SelectCommand="SELECT * FROM PRODUCT"
ConnectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True"
Runat="server" onselecting="DisplayXML" />
<br />
Click the button to generate "PRODUCT.xml"<br/>
<asp:Button runat="server" id="btnXML" Text="Generate XML"
OnClick="btnXML_Create"/>
<br/>
<asp:Label
id="lblResult"
Runat="server" />
<br />
<br />
<br />
<asp:HyperLink
id="HyperLink_XML"
Text="Show Updated XML"
NavigateUrl='~/WriteXML.aspx'
runat="server" />
<br />
</div>
</form>
</body>
</html>