Q:

SQL Server Views with asp.net

I have created a view called view_SelectAll_Student in SQL Server which retrieves all columns from single table name 
And I have a function that returns dataset or datatable using dataadapter somehow I get this error:

The request for procedure 'view_SellectAll_Student' failed because 'view_SellectAll_Student' is a view object.

Code:
public DataTable ViewStudentAll() 
{
      cons.Open();

      DataTable dt = new DataTable();

      cmd = new SqlCommand("view_SellectAll_Student", cons);
      cmd.Connection = cons;
      cmd.CommandType = CommandType.StoredProcedure;

      SqlDataAdapter adp = new SqlDataAdapter(cmd);

      adp.Fill(dt);
      cmd.Dispose();
      cons.Close();
      adp.Dispose();

      return dt; 
}

A:

Write it like this. If its a view you should SELECT it otherwise you wont get it.
cmd = new SqlCommand("SELECT * FROM view_SellectAll_Student",cons);
cmd.Connection = cons;
//cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
cmd.Dispose();
cons.Close();
adp.Dispose();
return dt;

TIP: While using a DataAdapter there is no need of con.Open() or con.Close() statement. DataAdapter itself will open and close it.

