-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.

0

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
@Asbat If the answer is helpful for you, please do not forget to mark it as answer. Thanks...
-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.