Hi
I am getting above error on below line
Session["dupRecords"] = "";
Session["totRecords"] = "";
Session["dupRecords"] = ((int?)Session["dupRecords"] ?? 0) + 1;
Thanks
Hi
I am getting above error on below line
Session["dupRecords"] = "";
Session["totRecords"] = "";
Session["dupRecords"] = ((int?)Session["dupRecords"] ?? 0) + 1;
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mohamed Azarudeen ZPosted May 24, 2023, 4:18 PM
To resol ve thiserror find below the updates code
In the updated code, i cast the retrieved values from
Session["dupRecords"]andSession["totRecords"]tointusing(int)(Session["..."] ?? 0). The(int?)part is not required since we are explicitly assigning a default value of 0 using the null coalescing operator (??) if the session variable is null or does not exist.After incrementing the values, we assign the updated values back to the session variables
Session["dupRecords"]andSession["totRecords"].By explicitly casting the values to
int, you can perform arithmetic operations on them without encountering any errors.