0
I’m having a problem when I’m going to assign the return of query
for a variable of the type object
she passes as null
.
I have other identical methods, and they work well, just the one that’s not passing the right value.
I could see that the DbValue
takes the right value, but at the time of assigning passes null.
My code is like this:
public string getEmailUsuario(string loginRede)
{
object email = "";
string Sql;
Sql = "SELECT EMAIL FROM VIEW_ADUSERS_LAZ_BR WHERE LOGIN_REDE = @LOGIN";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnIntranet"].ConnectionString;
SqlCommand cmd = new SqlCommand(Sql, conn);
cmd.Parameters.AddWithValue("@LOGIN", loginRede);
try
{
conn.Open();
email = cmd.ExecuteScalar(); <--- Aqui dá o erro. Passa "null"
if (email != DBNull.Value)
{
return email.ToString();
}
return "Sem email";
}
catch (Exception e)
{
_MSGERROR = e.Message.ToString();
return "Sem email";
}
finally { conn.Close(); }
}
Query the Database and see if returned any value. Most likely not.
– Marconi
I’ve done @Marconi and come back good ..
– AndreeH
its field LOGIN_REDE is varchar?
– Marconi
It’s a View query, it’s like Nvarchar.
– AndreeH