how to show web api data in my sql

RAVI 1,076 Reputation points
2025-03-27T11:27:19.29+00:00

Hello

We Have One Webapi running fine when we enter this url localhost/testapp/api/values/getdata

now we need to insert this data automtically in my sql table how to do so please guide step by step
{

"Table": [

{

  "Stduent_Join_Date": "12-MAR-2024",

  "Student_No": "LC/1820/24-25",

  "Student_Name": "MI"

},

{

  "Stduent_Join_Date": "18-MAR-2024",

  "Student_No": "LC/1821/24-25",

  "Student_Name": "LK"



}

]

}

ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
414 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 74,936 Reputation points
    2025-03-27T16:06:52.6033333+00:00

    using the dapper sql library:

    // call webapi
    var students = GetApiData();  
    
    // insert in table
    var sql = "insert MyTable (Stduent_Join_Date,Student_No,Student_Name) values(@Stduent_Join_Date,@Student_No,@Student_Name)";
    using (var connection = new SqlConnection(connString))
    {
        connection.Open();
        foreach(var student in students)
        {
            connection.Execute(sql, student);
        }
    }
    
    0 comments No comments

  2. SurferOnWww 4,231 Reputation points
    2025-03-28T00:53:26.2666667+00:00

    now we need to insert this data automtically in my sql table how to do so please guide step by step

    (1) Try using EF Core.

    (2) Create context class and entity class form your database. See Scaffolding (Reverse Engineering) for details.

    (3) Create controller and action method. It will be automatically done using scaffolding operation available in Visual Studio.

    (4) Modify the created action method if required to accept your data.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.