如何创建与C#中的SQL Server数据库的看法? [英] How can I create a view in a SQL Server database with C#?

查看:105
本文介绍了如何创建与C#中的SQL Server数据库的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

这篇关于如何创建与C#中的SQL Server数据库的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆