rosemary

rosemary

  • NA
  • 57
  • 20.2k

Error in return view

Jun 12 2018 11:14 PM
Error:Cannot implicitly convert type 'System.Web.Mvc.ViewResult' to 'System.Data.DataSet' 
 
samplecontroller.cs
 
 
public DataSet displaydetails(student s)
{
dbconnection db = new dbconnection();
DataSet ds = db.display(s);
s.show = ds;
return View(s);  //error shows here
  
 
dbconnection.cs 
 
public DataSet display(student s)
{
SqlCommand cmd = new SqlCommand("select * from register", con);
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
 
 
displaydetails.cshtml 
 
@model MVC_Homework.Models.student
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>displaydetails</title>
</head>
<body>
<div>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Place</th>
<th>Edit</th>
<th>Delete</th>
</tr>
@{
for(int i=0;i<Model.show.Tables[0].Rows.Count;i++)
{
var name = Model.show.Tables[0].Rows[i]["name"].ToString();
var age = Model.show.Tables[0].Rows[i]["age"].ToString();
var place = Model.show.Tables[0].Rows[i]["place"].ToString();
<tr>
<td>@name</td>
<td>@age</td>
<td>@place</td>
<td>@Html.ActionLink("Edit","edit")</td>
<td>@Html.ActionLink("Delete","delete")</td>
</tr>
}
}
</table>
</div>
</body>
</html>
 Anybody help to solve this.. 
thks in adv!! 
 

Answers (1)