如何在C#中使用sql select语句创建视图 [英] How to create view using sql select statement in C#

查看:381
本文介绍了如何在C#中使用sql select语句创建视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在asp.net应用程序中创建一个视图,并且创建视图的结果我想查询最新/前5视图中的行。



查看:

1)使用连接查询使用5个表创建视图。

Hi ,

I have a requirement to create an view in asp.net application, and with the result of created view i want to query latest /top 5 rows in the view.

View:
1)View is created using 5 tables using join query.

推荐答案

http://stackoverflow.com/questions/2303950/create-view-with-mutliple-tables-in-sql-server-2008



查看此链接
http://stackoverflow.com/questions/2303950/create-view-with-mutliple-tables-in-sql-server-2008

see this link


据我所知,您需要从创建的视图中获取前五(5)行。



我认为你可以使用这个SQL SELECT命令



As I understand your problem, you need to get first five(5) rows from the created view.

I think you can use this SQL SELECT Command

SELECT TOP 3 column1, column2
FROM yourViewName





或者你可以创建一个这样的新视图





Or else you can create a new view like this

CREATE VIEW yourNewViewName AS
  SELECT TOP 3 column1, column2
  FROM yourOldViewName


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();
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 select语句创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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