1

如何使用 C# 在 SQL Server 中动态创建视图?

4

2 回答 2

5

像这样的东西,显然你的连接代码会有所不同(更好):

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();
于 2008-12-03T11:33:40.760 回答
3

您可以使用以下代码编写视图查询:

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

执行查询。

于 2008-12-03T10:19:48.133 回答