I'm getting this exception in C # when I try to read SQL data. I am having doubts if this error is problem with my SQL or in C #.
My SQL code that does 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 in C # that reads 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 disclosing the code, but in their places I have the fields that verify data from the user context.
Can anyone help me with this? I can not receive the data from the table due to this exception!