Paweł Smejda
Paweł Smejda

Reputation: 2005

How to get View SQL Query within C#

I need to get View SQL Query to display it in some text box within C# CODE level. Each View is build upon part e.g. Select x From table and I want to retrieve it in my C# code, only that query using View name I already know. How to achieve this in C# maybe using ADO.NET?

Upvotes: 0

Views: 12159

Answers (2)

Petr Behenský
Petr Behenský

Reputation: 620

If I understand well you need DB schema. Maybe information from Retrieve all Views from DbConnection (for common DB types) can be useful for you.

Upvotes: 0

S2S2
S2S2

Reputation: 8502

Use ADO.Net SqlDataAdapter object's SelectCommand property to get the select query associated with the dataset/datatable, assuming this is what you want...

Below is the MSDN link for explanation of SelectCommand property:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.selectcommand.aspx

OK, if you want the underlying query for your database VIEW, then as it is stored on the database server, you can only get it by executing the stored procedure sp_helptext 'YOUR_VIEW_NAME' in sql management studio or even from ADO.Net in C#/VB.Net. Refer link below:

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

Upvotes: 1

Related Questions