-4
Advertisement a = new Advertisement
{
    userId = (int)Session["userID"],
    Brand = Brand,
    AdContent = filename,
    Duration = Duration,
};
Stefan
  • 17,448
  • 11
  • 60
  • 79
Jason
  • 3
  • 1
    Use `Convert.ToInt32(Session["userID"])` or `int.parse(Session["userID"])`. – Hadi Samadzad Jan 05 '20 at 10:23
  • 3
    [Under what circumstances may I add "urgent" or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) – jonrsharpe Jan 05 '20 at 10:24
  • 1
    When you searched for this problem, in what way did the answers not work for you? –  Jan 05 '20 at 10:24
  • 1
    Writing a question is the most important part if you need helps from the community, please you have to be more detailed and split title and question body – Roberto Conte Rosito Jan 05 '20 at 10:30

3 Answers3

2

Your Session variable is stored as string and needs to be converted.

You can use parse.

userId = int.Parse(Session["userID"]),

Do note: you have to be sure the numeric value is there, otherwise it will tbrow an exception, but your code already was assuming that.

Stefan
  • 17,448
  • 11
  • 60
  • 79
0

You must use Convert.ToInt32() function

Advertisement a = new Advertisement
{
    userId = Convert.ToInt32(Session["userID"]),
    Brand = Brand,
    AdContent = filename,
    Duration = Duration,    
};
vlada
  • 167
  • 15
0

you should convert userId from String To Int.

userId =int.Parse(Session["userID"]),

Or

userId =Convert.ToInt32(Session["userID"]),

Or

userId =Int32.TryParse(Session["userID"], out var value)? value :0,
Amin Golmahalleh
  • 3,585
  • 2
  • 23
  • 36