1
Answer

Error convertion a seesion string to an int

Rodney

Rodney

16y
2k
1

Hey everyone,

recently I am workign on a project where people are able to search wines and later get them from my database. I store the variables from the search form in Session which i later retrieve in the next page (I couldnt use the query string here since its too small). However i get a problem in retrieving my data.

 

 

First of all my search field put the data to a session, here is the code.

public partial class catalogus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BTNzoeken_Click(object sender, EventArgs e)
    {
        Session["searchkleur"] = DDLkleur.SelectedValue;
        Session["searchland"] = DDLland.SelectedValue;
        Session["searchdruifsoort"] = TXTdruifsoort.Text;
        Session["searchregio"] = DDLregio.SelectedValue;
        Session["searchjaar"] = TXTjaar.Text;
        Session["searchinhoud"] = DDLinhoud.SelectedValue;
        Session["searchprijs"] = DDLprijs.SelectedValue;
        Session["searchoverig"] = TXToverig.Text;
        Session["searchwijnnaam"] = TXTwijnnaam.Text;
        Session["searchproducent"] = TXTproducent.Text;

        Response.Redirect("resultaten.aspx");
    }
}

 

 

After this i will arrive at the resultaten.aspx page which holds the following code

public partial class resultaten : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["searchkleur"] != null)
        {
            string VARkleur = Session["searchkleur"].ToString();
            string VARland = Session["searchland"].ToString();
            System.Convert.ToInt32(VARland);
            string VARdruifsoort = Session["searchdruifsoort"].ToString();
            string VARregio = Session["searchregio"].ToString();
            string VARjaar = Session["searchjaar"].ToString();
            string VARinhoud = Session["searchinhoud"].ToString();
            string VARprijs = Session["searchprijs"].ToString();
            string VARoverig = Session["searchoverig"].ToString();
            string VARwijnnaam = Session["searchwijnnaam"].ToString();
            string VARproducent = Session["searchproducent"].ToString();

            LBLtest.Text = "Kleur " + VARkleur + "<br />Land " + VARland + "<br />Druifsoort " + VARdruifsoort + "<br />Regio " + VARregio + "<br />Jaar " + VARjaar + "<br />Inhoud " + VARinhoud + "<br />Prijs " + VARprijs + "<br />Overig " + VARoverig + "<br />Wijnnaam " + VARwijnnaam + "<br />Producent " + VARproducent;
        }
    }
}

 

and here's my aspx part with the SQL command:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ConnectionStrings:WijnhuisMDFConnectionString %>"
SelectCommand="SELECT [text] FROM [texten] WHERE textID = 26">
</asp:SqlDataSource>    
                                       
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BorderStyle="None"
DataSourceID="SqlDataSource2" GridLines="None" Width="240px">
<Columns>

<asp:BoundField DataField="text" HtmlEncode="False" SortExpression="text" />
</Columns>
</asp:GridView>

 

 

now i ve got 2 error messages: First one says that my landId cannot be converted to an integer so the session variable i stored as a string can't be converted to an int although i ve told C# to convert it.

2: i get an FormatException was unhandled y user code.

Does anyone know's whats wrong or how to solve it? I can share the project files if needed. Thanks in advance for your help :)

 
Answers (1)