0

I need to access a session variable called "usuario" created from another class.

First, I have the following class called Default.aspx.vb

Protected Sub btnvalidar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnvalidar.Click
    Dim fila As DataRow
    Dim nombre As String = ""

            For Each fila In tabla.Rows
                nombre = fila("referencia")
            Next
            Session.Add("usuario", nombre)

I need to access this variable from the following class called CConexion.vb

        _adaptador.SelectCommand = New MySqlCommand("select * from empresas where usuario=Session("usuario")", _conexion)

1 Answer 1

1

Your entire sql statement is enclosed in quotes. You want to add the session variable to the string instead:

"select * from empresas where usuario= '" + Session("usuario") +"'"

(You really should be using parameterized stored procedures)

Sign up to request clarification or add additional context in comments.

3 Comments

I did it but there is still an error in the variable, which is not declared, and I can't figure out how
Session state may not be available in your CConexion.vb class. I can't tell for sure based on your code snippets. You may have to find another way to pass the variable over. Maybe add a property named usario in that class and pass the value in.
Take a look at this answer: stackoverflow.com/questions/621549/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.