2
I’m getting this Exception in c# when I try to read SQL data. I’m wondering if this error is a problem with my SQL or C#.
My SQL code that makes the conversion is this:
`$
(SELECT ORDEM
FROM TABELA UP (NOLOCK)
WHERE UP.LAYOUT = r.LAYOUT
AND TIPOUSUARIO =CASE
WHEN TIPOUSUARIO = 2 THEN 'A'
WHEN TIPOUSUARIO = 3 THEN 'P'
END
AND CODUSUARIO = @CODUSUARIO)
, r.IDSQL+100) AS ORDER
$
And the code on the c# that reads it is this:
using (SqlConnection connection = new SqlConnection(WebConfig.ConnectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = @"sp_vm_getUserItems";
command.Parameters.AddWithValue("@...", context.UserId);
command.Parameters.AddWithValue("@USERTYPE", (int)context.UserType);
command.Parameters.AddWithValue("@...", context.AffiliateId);
command.Parameters.AddWithValue("@..", context.CorporateId);
command.Parameters.AddWithValue("@...", context.CourseId);
command.Parameters.AddWithValue("@..", context.SchoolYearId);
command.Parameters.AddWithValue("@...", context.LevelEducationId);
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
result.Add(new ReportItem() { Layout = Convert.ToInt32(reader[0]), Tipo = Convert.ToString(reader[1]), Ordem = Convert.ToInt32(reader[2]) });
}
$
Note: The dots are simply to avoid disclosure of the code, but in their places I have the fields that check data of the user context.
Can anyone help me with that? I can’t receive table data due to this Exception!
Please don’t write in upper case.
– Jéf Bueno
sorry, it’s because I was playing with sql.... I’ll change
– hashtah29
TIPOUSUARIO is varchar? and CODUSUARIO = @CODUSUARIO are of the same type? select is just that?
– Marco Souza
TIPOUSUARIO is varchar, Cod user is varchar , select has other parts, but the problem is in the same conversion. wanted to do a CASE WHEN 'A' Then 2 When 'P' then 3 but n ran tb n
– hashtah29