Click here to Skip to main content
15,911,789 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted

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();
 
Share this answer
 
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

SQL
SELECT TOP 3 column1, column2
FROM yourViewName


Or else you can create a new view like this

SQL
CREATE VIEW yourNewViewName AS
  SELECT TOP 3 column1, column2
  FROM yourOldViewName
 
Share this answer
 
Comments
Jyothi.Gowda 27-Mar-12 3:36am    
Hello thanks for your reply,

I have created the view using 5 tables with Join Command. and i am able to fetch top 5 records using Select with Top , i want to create the same view in my asp.net application. using C# code, and need to query latest 5 records with the created View.using C# code
Thilina Chandima 27-Mar-12 21:35pm    
Jyothi I didn't get your question, I mean if you can write a view in sql server you can call that view inside your c# code for that you can use sqlcommand or something to execute that view.

otherwise explain your question more detail manner then sometime i can help.
http://stackoverflow.com/questions/2303950/create-view-with-mutliple-tables-in-sql-server-2008

see this link
 
Share this answer
 
Comments
Jyothi.Gowda 26-Mar-12 1:57am    
Hi, Thanks for your reply,
i have already created in Sql Server, i required help in C#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900