Find information in the database in one row of SQL code per logged-in user

1

I've been able to fetch all dates from the database. However, I would like to search through a specific ID that is logged into the system. Per session, in case. But this code is giving error in the part where I put the HttpContext. Any suggestions on what to change?

public static Dictionary<object, object> SelecionaLinhasBancoLista()
    {

        Dictionary<object, object> dic = new Dictionary<object, object>();

        string sql = "";
        sql = "SELECT dayname(carrinho.Data), count(day(carrinho.Data)) as quantidade FROM foodintime.carrinho where carrinho.restauranteid = "+ HttpContext.Current.Session["ID"] +"group by day(carrinho.Data)";

        using (var ctx = new Context())
        using (var cmd = ctx.Database.Connection.CreateCommand())
        {
            ctx.Database.Connection.Open();
            cmd.CommandText = sql;
            using (var reader = cmd.ExecuteReader())
            {
                var model = Read(reader).ToList();

                string[] dias = new string[] { "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo" };

                foreach (var item in model)
                {


                    dic.Add(item.GetValue(0), item.GetValue(1));

                }
            }
        }
    
asked by anonymous 19.11.2016 / 17:56

1 answer

2

Allan

A space is missing between the quotation marks and group by in your select.

"+ HttpContext.Current.Session["ID"] +" group by
    
19.11.2016 / 23:11