How can I create a view in a SQL Server database w

2020-07-30 04:13发布

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

2条回答
看我几分像从前
2楼-- · 2020-07-30 04:53

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

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

Execute the query.

查看更多
Emotional °昔
3楼-- · 2020-07-30 05:04

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();
查看更多
登录 后发表回答