简体   繁体   English

如何将html表数据以可以保存在sql数据库中的方式传输到Jquery脚本?

[英]How can I transfer html table data to Jquery script in a way that I can save it in the sql database?

I want to get table row data in the below html code into jquery like a data table in C#, so I can save it in SQL DB. 我想将下面的html代码中的表行数据像c#中的数据表一样放入jquery中,因此可以将其保存在SQL DB中。

How can i do this? 我怎样才能做到这一点?

<table class="table table-bordered" id="table_GemList">
    <thead>
        <col style="width: 25%">
        <col style="width: 25%">
        <col style="width: 25%">
        <col style="width: 25%">
    </thead>
    <tbody id="GemListBody">
        <tr>
            <td>Oval</td>
            <td>Red</td>
            <td>2.23</td>
            <td><span class="glyphicon glyphicon-trash"></span></td>
        </tr>
        <tr>
            <td>Oval</td>
            <td>Red</td>
            <td>2.23</td>
            <td><spanclass="glyphicon glyphicon-trash"></span></td>
        </tr>
    </tbody>
</table>      
  1. Iterate through the table <tr> s & <td> s via. 通过<tr><td>遍历表。 jQuery and create a JSON array with the values. jQuery并使用值创建一个JSON数组。
  2. Post back the array to the server. 将阵列发回到服务器。
  3. At server: Convert the array to DataTable . 在服务器上:将数组转换为DataTable
  4. Save the datatable directly to SQL database using SqlBulkCopy.WriteToServer 使用SqlBulkCopy.WriteToServer将数据表直接保存到SQL数据库

To save or insert data into database you can use postback into the server (which will refresh the page) or, using AJAX you can provide the functionality without refreshing the browser. 要将数据保存或插入数据库中,可以使用postback到服务器(这将刷新页面),也可以使用AJAX提供功能而无需刷新浏览器。 JQuery Ajax provides you an easier option to easily integrate Ajax functionality in web applications. JQuery Ajax为您提供了一个更简单的选项,可以轻松地将Ajax功能集成到Web应用程序中。 Check this article may helpful for you : How to Save or Insert Data into SQL Server Databse using JQuery AJAX in ASP.Net C# 检查本文可能对您有所帮助: 如何在ASP.Net C#中使用JQuery AJAX将数据保存或插入到SQL Server Databse中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建新的数据记录并将其保存到SQL数据库表中 - How can I create a new record of data and save it to the SQL database table 我可以在SQL Server数据库中保存“对象”吗? - Can I save an 'Object' in a SQL Server database? 如何使用Azure函数或逻辑应用程序将数据保存到sql数据库中? - How can I use Azure functions or logic apps to save data into sql database? 如何将URL中的XmL数据保存到数据库中 - how can i save XmL data from a URL into my database 如何从数据库表中以编程方式生成“插入”数据脚本文件? - how i can generate programmatically “insert into” data script file from a database table? 如何将 GridView 中的数据保存到数据库中? - How I can save the data from GridView to the database? 如何在特定的SQL数据库中存储AspNetUser表? - How can I store AspNetUser table in a certain SQL Database? 如何从SSMS禁用SQL Server数据库中的表 - How can I disable a table in a SQL Server database from SSMS 如何从Web API重定向将数据传输到html页面? - How can I transfer data to html page from Web API redirect? 如何从datagridview保存到数据库? - How can I save from datagridview to database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM