Jump to content
Sign in to follow this  
killzone3

Use of unassigned local variable 'clausula'[RESOLVIDO]

Recommended Posts

killzone3

boas

Eu tinha a variavel Clausula assim=string clausula=null e assim nao me dá o erro,mas cada vez que carrego no botao a clausula vai ficar null,por isso mudei para string clausula,mas agora da me erro no clausula +=....,porque?

Obrigado

protected void Button3_Click1(object sender, EventArgs e)
    {

        string clausula;
        
        int index = 1;
        
        if (index == 1)
        {
            clausula = "" + DropDownList5.SelectedItem.Value +" LIKE '%" + TextBox1.Text + "%'";
        index=index +1;
        }
        else if (index > 1)
        {
            
            clausula += "and" + DropDownList5.SelectedItem.Value + " LIKE '%" + TextBox1.Text + "%'";
        index=index+1;

        }
        Session["clausula"] = clausula;
    }

Share this post


Link to post
Share on other sites
killzone3

Soluçao:

Utilizei class(s) e já deu:

 

 class index1
    {

        public static int index = 1;

    }

    class clausula1
    {

        public static string clausula = null;

    }
    protected void Button3_Click1(object sender, EventArgs e)
    {
        
         
        if ( index1.index==1)

        {
            clausula1.clausula = "" + Convert.ToChar(32) + DropDownList5.SelectedItem.Value + " LIKE '%" + TextBox1.Text + "%'";
                index1.index++;
        }

        else if (index1.index > 1)
            {

                clausula1.clausula += "and" + Convert.ToChar(32) + DropDownList5.SelectedItem.Value + " LIKE '%" + TextBox1.Text + "%'";
            }

            Session["clausula"] = clausula1.clausula;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.