Reputation:
Please helpme how can i execute View from C#
var emp = new List<Employee>();
using (SqlConnection con = abs.Getconnection())
{
con.Open();
SqlCommand cmd=new SqlCommand("viewEmployee",con);
cmd.CommandType=CommandType.Text;
SqlDataReader rdr=cmd.ExecuteReader();
if(rdr.HasRows==true){
while(rdr.Read()){
Employee employee=new Employee();
employee.EmpName=rdr["EmpName"].ToString();
emp.Add(employee);
Here im Getting Error as This is view object.
Upvotes: 0
Views: 3624
Reputation: 8980
Just change this line
SqlCommand cmd=new SqlCommand("viewEmployee",con)
to this
SqlCommand cmd=new SqlCommand("select * from viewEmployee",con)
View is like a table, so you have to select rows from it like you do from table.
Upvotes: 5