-2

I am new to Asp.net MVC and I am also new to SQL server. I am able to write a long query with joins etc to retrieve the required data in MS SQL server. Now I want to display the query result in my MVC project as a new page. I dont want to use Linq because it will be another Big job to transform that sql query in Linq. I searched getdatafromquery() method but couldnt find any good examples. I am not even sure what I need to do to implement it. Can any one please let me know what will be the best way to achieve it. Thanks.

Dr. Mian
  • 3,334
  • 10
  • 45
  • 69

2 Answers2

3

I suggest you to use Entity Framework Code-First by following the steps mentioned on Getting Started with Entity Framework 6 Database First using MVC 5

On the other hand, regarding to "retrieving data from sql server using query in ASP.net MVC" you might have a look at my answer on Execute raw SQL query in ASP.NET MVC, database first mode

Murat Yıldız
  • 11,299
  • 6
  • 63
  • 63
  • Thanks a lot. I am working on an existing project which is already using entity framework etc. The second part (your answer) is what I am looking for. I am trying to see if i can follow it. – Dr. Mian Mar 24 '15 at 15:09
  • You are welcome. But for the next projects, I strongly recommend to try EF Code First as it makes very easy performing the data field changes. – Murat Yıldız Mar 24 '15 at 15:13
  • @Asbat If the answer is helpful for you, please do not forget to mark it as answer. Thanks... – Murat Yıldız Oct 28 '16 at 06:23
-2

So I achieved this by performing the following steps.

  1. Create the sql-server query that you want to execute from C#.
  2. In a controller create an ActionResult method for writing the query and connectionstring to the database.
  3. Create a model that contains the same number of properties that is returned by the query
  4. Create a view.
Dr. Mian
  • 3,334
  • 10
  • 45
  • 69