
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.

Shirsendu NandiPosted Apr 11, 2011, 4:33 AM
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
ArshadPosted Apr 11, 2011, 3:32 AM
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
rahulPosted Mar 29, 2011, 4:17 AM
ArshadPosted Mar 29, 2011, 2:27 AM
http://www.asp.net/mvc