problème d'objet session dans une requête
Bonjour
Dans mon site, j'ai codé un gridview avec un AccessDataSource pour accéder à ma base.
Pour trier ce gridview, je manipule la requête du AccessDataSource en fonction de données entrées dans des Textbox ou des combo.
Tout à l'air de bien fonctionner, sauf que quand j'utilise l'objet session pour stocker et réutiliser une requête, çà plante. il m'affiche :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 56: where = filtrerpartcmb(where, txtnom, "nom");
Line 57: where = filtrercmb(where, cmbpromo);
Line 58: string test = Session["reqdebase"].ToString() + where;
Line 59: //Response.Write(where);
Line 60: if (Session["req"] != null)
Source File: d:\www\masteriens-misl.org\htdocs\index.aspx.cs Line: 58
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
contributions.btntri_Click(Object sender, EventArgs e) in d:\www\masteriens-misl.org\htdocs\index.aspx.cs:58
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102 |
Selon moi celà veut dire que l'objet session n'est pas instancié, chose que je ne comprends pas.
Voici le code C# de ma page :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public partial class contributions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (Session["req"] != null)
bdmasteriens.SelectCommand = Session["req"].ToString();
}
else
Session["reqdebase"] = bdmasteriens.SelectCommand.ToString();
//Response.Write(Session["reqdebase"].ToString());
}
private string filtrerpartcmb(string where, TextBox ctrl, string champ)
{
if (ctrl.Text.Trim() != "")
{
if (where == "")
where = " where ";
else
where += " and ";
where += champ + @" like '%" + ctrl.Text + "%'";
}
return where;
}
private string filtrercmb(string where, DropDownList ctrl)
{
if (ctrl.Text.Trim() != "")
{
if (where == "")
where = " where ";
else
where += " and ";
where += ctrl.DataTextField + "='" + ctrl.SelectedItem + "'";
}
return where;
}
protected void btntri_Click(object sender, EventArgs e)
{
string where = "";
where = filtrerpartcmb(where, txtnom, "nom");
where = filtrercmb(where, cmbpromo);
string test = Session["reqdebase"].ToString() + where;
//Response.Write(where);
if (Session["req"] != null)
{
if (Session["req"].ToString() != test)
{
bdmasteriens.SelectCommand = test;
Session["req"] = test;
}
else
bdmasteriens.SelectCommand = Session["req"].ToString();
}
else
{
bdmasteriens.SelectCommand = test;
Session["req"] = test;
}
dtgindex.DataBind();
//Response.Write(Session["req"].ToString());
} |
Ce qui est bizarre, c'est que par moment çà marche parfaitement, mais la plupart du temps, çà m'affiche le message d'erreur.
SI quelqu'un est inspiré, merci d'avance pour son aide.