left hand side of an assignment must be a variable

Trying to put an integer data from database(Linq to sql) into a label getting this error exception:

left-hand side of an assignment must be a variable property or
indexer

Code:

protected void Page_Load(object sender, EventArgs e)
{
   DataClassesDataContext data = new DataClassesDataContext();

   var visit = (from v in data.SeeSites where v.Date == todaydate select v).FirstOrDefault();
   int seennow = visit.See; // On This line I can put data in seenow variable, no problem

   Convert.ToInt64(lblSeeNow.Text) = visit.See;   // exception error appears here
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try:

if (visit.See != null) {
    lblSeeNow.Text = visit.See.ToString();
}

You cannot assign something to a function result. In your case lblSeeNow.Text is of type String hence usage of ToString(); method of your Int value.

Method 2

You need to use

 lblSeeNow.Text = visit.See.ToString();

Method 3

Convert.ToInt64(lblSeeNow.Text) = visit.See;

As you mentioned, this is the issue.

Convert.ToInt64 is a method. But you’re trying to save a value to it.

You can’t.

Just do this

lblSeeNow.Text = visit.See.ToString();

Method 4

I think you want

lblSeeNow.Text = visit.See.ToString();

You can’t assign anything to

Convert.ToInt64(lblSeeNow.Text)

because it evaluates to a number.

Method 5

Convert.ToInt64(lblSeeNow.Text) isn’t a variable. It takes the value in lblSeeNow.Text and converts it to a long. There isn’t a variable to store stuff in anymore.

You probably want this:

lblSeeeNow.Text = visit.See.ToString();

Method 6

You should convert the integer to string, also add a check for being sure that visit is not null

lblSeeNow.Text = visit != null ? visit.See.ToString() : string.Empty


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x