user240141
user240141

Reputation:

Executing T-Sql View from ADO.NET

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.

Upvotes: 4

Views: 6474

Answers (3)

MikeTWebb
MikeTWebb

Reputation: 9279

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();

Upvotes: 0

Oded
Oded

Reputation: 499402

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.

Upvotes: 2

John Saunders
John Saunders

Reputation: 161831

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.

Upvotes: 9

Related Questions