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

ked*_*the 1 c# sql sql-server views

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

Coo*_*der 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();
Run Code Online (Sandbox Code Playgroud)