Solved

c# execute view

Posted on 2009-05-19
3
867 Views
Last Modified: 2013-12-17
I C# It is possible to execute a SQL storedprocedure using the following code

DbCommand dbCommand = db.GetStoredProcCommand("StoredProcedureName");

Does anybody know how I can I execute a grad the data from a view.

specifical the SQL server system view for master.sys.sysdatabases.

for example

DbCommand dbCommand = db.GetViewCommand("master.sys.sysdatabases");
0
Comment
Question by:Mr_Shaw
  • 2
3 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 24423671
Hi,

You don't execute a view in the way you do with a stored procedure. You just select * from the view and it will return everything.

See here:

http://msdn.microsoft.com/en-us/library/9hy8csk1.aspx

Cheers,

Lee
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 24423680
In that example, the queryString string variable, replace with

select * from insertViewNameHere

and it will do what you want.

Cheers,

Lee
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31597511
thanks
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question