
How to fetch one row from database in asp.net mvc2
I'm building an online exam system,where questions will be fetched from database and displayed to the user,just like this where one question is displayed at a time upon clicking next next question is fetched,can any one suggest something to do this.


ArshadRank #2,492 · 564 reputationPosted Mar 28, 2011, 10:27 PM EDT
http://www.asp.net/mvc
rahul14 reputationPosted Mar 29, 2011, 12:17 AM EDT
ArshadRank #2,492 · 564 reputationPosted Apr 10, 2011, 11:32 PM EDT
Please find the below link, just download the book from there, its based on MVC and their is one application that is fully explained in this book.
http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf
just download the book and go through.
Regards,
Arshad
Shirsendu NandiRank #246 · 10.2K reputationPosted Apr 11, 2011, 12:33 AM EDT
rahul.
you can use Linq in to your controller class for your particular action result method.I am givving below a sample example where you will find the gender name and a particular id for a givven row.
For that i first i take the all records from the table in to the list.see the below example
[HttpPost]
public ActionResult CreateLogin(Employee Employee)
{
//string time = string.Format("{0:hh:mm tt}", DateTime.Now);
string time = string.Format("{0:hh tt}", DateTime.Now);
try
{
//if (s1 == "07 PM" || )
//{
List
foreach (var obj in _db.Employee.ToList())
{
lstEmployee.Add(obj);
}
var vargender = (from Gender in lstEmployee
where Gender.Email == Employee.Email && Gender.Password == Employee.Password
select Gender).ToList ();
foreach (var gen in vargender)
{
gender = gen.Gender;
id = gen.CabId;
}
if ((gender == "Female" && (time == "12 PM")) ||(gender == "Male") )
{
foreach (var obj in lstEmployee)
{
if (obj.Email == Employee.Email && obj.Password == Employee.Password)
{
//return RedirectToAction("CabBook");
Employee.CabId = id;
return RedirectToAction("CabBook1", new { id = Employee.CabId });
//return RedirectToAction("CabBook1", id);
}
}
return View(Employee);
}
return View(Employee);
}
catch
{
return View();
}
}
#endregion LoginEventforEmployee