Reputation: 3
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!
Upvotes: 0
Views: 424
Reputation: 20415
Shouldn't you be using ==
?
where journalist.JournalistId == Convert.ToInt16(Session["bruker"].ToString())
Upvotes: 2
Reputation: 63105
try below
Journalist brukernavn = dbKobling.Journalists.SingleOrDefault(x => x.JournalistId ==
Convert.Int16(Session["bruker"].ToString()));
Upvotes: 0