Search information in the database in one SQL code line per logged in user

Asked

Viewed 59 times

1

I have already been able to search all the dates of the database. However, I would like to search through a specific ID that is logged in to the system. Per session, in case. But this code is giving error in the part where I put 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));

                }
            }
        }
  • And what’s the mistake?

1 answer

2


Allan

is missing a space between quotes and group by in your select.

"+ HttpContext.Current.Session["ID"] +" group by
  • I can’t believe that’s all it was! .

  • kkkk, this happens I think more times than I would like. If we need are the orders.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.