locked
From Table to Database RRS feed

  • Question

  • User-333609119 posted

    Where is a good place to learn how to insert data from a table into a database?

    Saturday, September 14, 2019 10:18 PM

Answers

  • User-333609119 posted

    Oh, my bad. I meant through JavaScript/jQuery. I already know how to use EF Core and ADO.

    The part I need help with learning how to do from the attached image is when a user clicks on Enter, the 4 drivers are inserted into a table in my database.

    https://imgur.com/a/JvyQysS

    Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 15, 2019 2:05 PM

All replies

  • User-2054057000 posted

    You should learn to develop CRUD Application which will help you to learn. There are 2 ways to add the data to the database:

    1. ADO.NET
    2. Entity Framework Core

    I recommend you to start with ADO.NET and then move to Entity Framework Core. 

    Sunday, September 15, 2019 5:44 AM
  • User-333609119 posted

    Oh, my bad. I meant through JavaScript/jQuery. I already know how to use EF Core and ADO.

    The part I need help with learning how to do from the attached image is when a user clicks on Enter, the 4 drivers are inserted into a table in my database.

    https://imgur.com/a/JvyQysS

    Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 15, 2019 2:05 PM
  • User665608656 posted

    Hi Nicholas,

    According to your description, if you want to use js or jquery to save data into database, I recommend you can use ajax with jquery to pass the json string to your controller ,then store these 4 drivers in your database in your controller method.

    Here is an example , you can refer to it:

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>C0916_2159733</title>
    
        <script src="~/Scripts/jquery-3.3.1.min.js"></script>
        <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
        <script>
        $(document).ready(function () {
            $("#btnSave").click(function () {
    // you can get these data by using like this : $("#firstName").val() var things = [ { FirstName: "aaa", LastName: 'yellow',EmailAddr:"xxxxxxxxx" }, { FirstName: "bbb", LastName: 'blue',EmailAddr:"fffffffffffff" }, { FirstName: "ccc", LastName: 'red',EmailAddr:"yyyyyyyyyy" }, { FirstName: "ddd", LastName: 'red',EmailAddr:"kkkkkkkk" }, ]; things = JSON.stringify({ 'things': things }); $.ajax( { type: "POST", //HTTP POST Method url: "/Default/AddEmployee", // /Controller/View data: things, contentType: 'application/json; charset=utf-8', dataType: 'json', success:function(){ alert("success"); } }); }); }); </script> </head>
       [HttpPost]
            public ActionResult AddEmployee(List<Employee> things)
            {
                Entities2 entities2 = new Entities2();
                foreach (var item in things)
                {
                    entities2.Employees.Add(item);
                }
                entities2.SaveChanges();
                return View();
            }

    Here is a full example , you can also refer to it : Pass (Send) List of objects from View to Controller using jQuery AJAX in ASP.Net MVC

    Best Regards,

    YongQing.

    Monday, September 16, 2019 8:09 AM