How do I create a view dynamically in SQL Server using C#?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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();
回答2:
You can use the following code to write the query for a view:
query = " Create View [Viewname] Select ....";
Execute the query.