5
Answers

Not Getting Data Nullable Exception

public ActionResult Logout(UserProfile objUser)
{
{
if (ModelState.IsValid)
{
using (SessionEntities Db = new SessionEntities())
{
var obj = Db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
if (obj != null)
{
Session["UserName"] = objUser.UserName.ToString();
// Session["UserName"] = obj.UserName.ToString();
// Session.Remove(a.ToString());
Session.Abandon();
return RedirectToAction("Login");
}
else
{
return RedirectToAction("Admin");
}
}
}
}
return RedirectToAction("UserDashBoard");
}
Answers (5)
0
Ankit Sharma

Ankit Sharma

NA 8.8k 140.9k 7y
Hi ,
 
This code has errors.
 
You are using  s[i].total=0; 
 
This won't work coz
 
1. s is not an array 
2. you have not set any values to the int variable i 
 
You have to create an array of structure like this
 
struct student arr[10]; 
 
then you have to iterate loop to set values
 
Now scanf("%s",&s[i].name); is also wrong as format '%s' expects argument of type 'char *', but here it has type 'char (*)[20]'
 
change it to
 
scanf("%s",s[i].name); 
 
Please make these changes and let me know if any issues
 
I have edited the code and you can find the fully edited and working code here
 
https://ide.geeksforgeeks.org/sYBZrfXFZ9