如何使用C#在SQL Server数据库中创建视图?

问题描述:

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

这样的事情,很明显你的连接代码会有所不同(更好):

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(); 

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

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

执行查询。