tags:

views:

43

answers:

3

Is this possible to execute a View from C# code. If it is then I would like to know if parametrized views exists and how should I use them. Parametrized means same parameters we use in Stored Procedures for stating where conditions.

+4  A: 

One does not execute views. One executes a query. If the query selects rows from a view or from a table, ADO.NET doesn't know or care.

John Saunders
Thanks I got it. I was bit confused. Views acts as a virtual table and we can create sp or query on that based on suitable condition.
Amit Ranjan
+2  A: 

You treat a view the same way you would treat a table (for selecting, that is).

A parameterized query that would use a table in the FROM clause would work just as well with a view.

Don't confuse views with stored procedures - stored procedures are executed, views simply are. You read data from a view through a query, using a SELECT statement.

Oded
+1  A: 

Think of a veiw as straight SQL where the View name replaces a table name: i.e. select * from v_employee_department...vs...select * from employee where v_employee_edpartment is a view that joins the employee table and department table

     // Declare connection string.
     string connStr = Properties.Settings.Default.ConnectionString;
     OracleConnection cn = new OracleConnection(connStr);

     // STEP 1: Execute command 
     string selectCommandTotal = "SELECT ID FROM <SOME_VIEW> WHERE <SOME_FIELD> = <SOME_VALUE> ";
     OracleCommand cmdGetTotals = new OracleCommand(selectCommandTotal, cn);

     cmdGetTotals.Connection.Open();
     OracleDataReader rdrGetTotals = cmdGetTotals.ExecuteReader();
MikeTWebb