Sql Reader returning null value

1

I'm running a datareader , but it does not return any value, I've already checked the table and the conditions ( where ) of select exist in the table.

The code follows below:

public void consulta()
    {
        string sqltring = @"Data Source=tptspo01sql01.database.windows.net;Initial Catalog=Tptecnologia;Integrated Security=False;User ID=******;Password=******;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False";
        string _sql = string.Empty;
        SqlConnection sqlcon = new SqlConnection(sqltring);

        string usu, pass, idemp1, idusu;
        usu = textBox1.Text;
        pass = textBox2.Text; 

        try
        {
            sqlcon.Open();

            _sql = "SELECT * FROM Login WHERE usuario = @usuario AND Passwd = @Passwd";

            SqlCommand cmd = new SqlCommand(_sql, sqlcon);

            cmd.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usu;
            cmd.Parameters.Add("@Passwd", SqlDbType.VarChar).Value = pass;

            SqlDataReader reader2 = cmd.ExecuteReader();


            while (reader2.Read())
            {
                idemp1 = reader2["Id_empresa"].ToString();
                idusu = reader2["id_usu"].ToString();

                MessageBox.Show("id empresa " + usu + "\b" + "is usuario " + pass);
            }

        }

        catch(SqlException error)
        {
            MessageBox.Show(error + "Na segunda consulta de id empresa");
        }

        finally
        {
            sqlcon.Close();
        }



    }
    
asked by anonymous 04.06.2016 / 18:06

1 answer

0

Thanks for the help, I decided, what happened was:

The two data I was looking for in the table, are of type INT, and I was wanting to run a datareader, which looks for values of type string. then the error, I solved, applying a query of the type executescalar.

Thanks

    
05.06.2016 / 00:26