ciao a tutti...ho scritto del codice e non capisco perchè non funzioni...a livello logico dovrebbe andare e invece...nulla...nel codice che posterò metterò un commento nel punto in cui mi da l errore
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
String connectionString = "dati per la connessione al db;";
SqlConnection cn = new SqlConnection(connectionString);
SqlDataReader myReader = null;
XmlDocument doc = new XmlDocument();
String testoquery = "";
XmlNodeList nodi;
doc.Load("C:/.../queries.xml");
nodi = doc.GetElementsByTagName("query");
foreach (XmlNode nodo in nodi)
{
if (nodo.FirstChild.InnerText == "default")
testoquery = nodo.FirstChild.NextSibling.InnerText;
}
SqlCommand cmd = new SqlCommand(testoquery, cn);
try
{
cn.Open();
myReader = cmd.ExecuteReader();
dt.Load(myReader);
gvdati.DataSource = elaboraquery(dt,cn,myReader);
gvdati.DataBind();
myReader.Close();
}
catch (SqlException)
{
}
finally
{
cn.Close();
}
}
public DataTable elaboraquery(DataTable dt,SqlConnection cn, SqlDataReader myReader)
{
XmlDocument doc = new XmlDocument();
String testoquery = "";
XmlNodeList nodi;
doc.Load("C:/.../queries.xml");
nodi = doc.GetElementsByTagName("query");
DataTable app = new DataTable();
foreach (DataRow row in dt.Rows)
{
foreach (XmlNode nodo in nodi)
{
if (nodo.FirstChild.InnerText == "deannocorrente")
{
myReader = null;
testoquery = nodo.FirstChild.NextSibling.InnerText;
SqlCommand cmd = new SqlCommand(testoquery, cn);
myReader = cmd.ExecuteReader();
app.Load(myReader);//IN QUESTO PUNTO MI TORNA AL CATCH DEL METODO Page_Load
if (app.Columns["libro_orestato"] != null)
{
dt.Columns.Add(app.Columns["libro_prestato"]);
}
else
dt.Columns.Add("");
}
}
}
return dt;
}
secondo voi perchè mi da l errore che ho messo nel commento?