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();
}
}