0

I am using C# and have a login session.

The site will only view the news (nyhet) that the journalist have written. (It's a site where the journalist can edit the news)

protected void FyllNyhetDropDownList() 
{
    using (NyhetAdminDataContext dbKobling = new NyhetAdminDataContext())
    {            
        Journalist brukernavn = (from journalist in dbKobling.Journalists
                                 where journalist.JournalistId = Convert.ToInt16(Session["bruker"].ToString())
                                 select journalist).SingleOrDefault();

        List<Nyhet> nyhetliste = (from nyhet in dbKobling.Nyhets
                                  select nyhet).ToList();

        if (nyhetliste.Count() > 0)
        {
            NyhetDropDowwnList.DataTextField = "Tittel";
            NyhetDropDowwnList.DataValueField = "NyhetId";
            NyhetDropDowwnList.DataSource = nyhetliste;
            NyhetDropDowwnList.DataBind();
        }
    }
}

It's here all go wrong. Can anyone help?

where journalist.JournalistId = Convert.ToInt16(Session["bruker"].ToString())

I get the error message

Cannot implicitly convert type 'int' to 'bool'

Thanks for any help!

1
  • 2
    The where clause requires a conditional statement. You're using the = assignment operator and not the == comparison operator. I would also caution you against the use of Int16 if you need values beyond 2^16 for the JournalistId. Commented Jan 30, 2014 at 18:03

2 Answers 2

2

Shouldn't you be using ==?

where journalist.JournalistId == Convert.ToInt16(Session["bruker"].ToString())
Sign up to request clarification or add additional context in comments.

Comments

0

try below

Journalist brukernavn = dbKobling.Journalists.SingleOrDefault(x => x.JournalistId ==                                                 
                     Convert.Int16(Session["bruker"].ToString()));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.