How do I create a view in a SQL Server database using C #?

How do I create a dynamic view in SQL Server using C #?

+1


source to share


2 answers


Something like this, obviously your connection code will be different (better):



SqlConnection conn = null;
conn = new SqlConnection("yourConnectionString");
conn.Open();
string strSQLCommand = "CREATE VIEW vw_YourView AS SELECT YOurColumn FROM YourTable";
SqlCommand command = new SqlCommand(strSQLCommand, conn); 
string returnvalue = (string)command.ExecuteScalar(); 
conn.Close();

      

+4


source


You can use the following code to write a request for a view:

query = " Create View [Viewname] Select ....";

      



Complete your request.

+3


source







All Articles