简体   繁体   English

如何从asp.net中的html表中将数据插入数据库

[英]How to insert data into database from html table in asp.net

How do I add data into a database from an HTML table? 如何从HTML表中将数据添加到数据库中?

My table is like this: 我的桌子是这样的:

html += "<table>";
html += "<tr><th>" + "A" + "</th><th>" + "B" + "</th><th>" + "C" + </th></tr>";
html += "<tr><td>" + "0" + "</td><td>" + "1" + "</td><td>" + "2" + </td></tr>";
html += "</table>";

I'm calling the HTML from the server side. 我从服务器端调用HTML。

if you like plain HTML, you can use a JavaScript framework like Knockout.js along with it. 如果你喜欢纯HTML,你可以使用像Knockout.js这样的JavaScript框架。 Knockout.js allows you to inject data into HTML using JavaScript View Models. Knockout.js允许您使用JavaScript View Models将数据注入HTML。 A button click can be assigned to a JavaScript function in the View Model. 可以在视图模型中为按钮分配按钮。 The JavaScript function can do an AJAX post to call a controller action method on the server side - which will insert the data into the database. JavaScript函数可以执行AJAX帖子来调用服务器端的控制器操作方法 - 这将把数据插入到数据库中。

For more information about knockout, check http://knockoutjs.com 有关淘汰赛的更多信息,请访问http://knockoutjs.com

Use System.Text.RegularExpressions (Regex) to search pattern to replace the table tag: 使用System.Text.RegularExpressions(Regex)搜索模式以替换表标记:

replace <tr><th> and <tr><td> with blank, 用空白替换<tr><th><tr><td>

replace </th></tr> and </td></tr> with ^^~~~~~~~~~~^^ indicates endline. ^^~~~~~~~~~~^^替换</th></tr></td></tr>表示结束。

replace </td><td> with ||^^^^^^^^^|| ||^^^^^^^^^||替换</td><td> indicates delimeters 指示分隔符

string html = // your html table goes here
string[] lines = html.Split(new string[] { "^^~~~~~~~~~~^^" }, StringSplitOptions.None);
// now your html table is divided into lines, which means rows

// lines[0] = // the header
// lines[1] = // row 1
// lines[2] = // row 2
// lines[3] = // row 3
// ...
// ...

// line 1 is the header/column name
string[] columns = lines[0].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None);

// columns[0] = // 1st column name
// columns[1] = // 2nd column name
// columns[2] = // 3rd column name
// ...
// ...

for (int i = 1; i < lines.Length; i++)
{
    string[] data = lines[i].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None);
    // data[0] = // 1st data
    // data[1] = // 2nd data
    // data[2] = // 3rd data 
    // ...  
    // ...
}

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

相关问题 如何使用 c# asp.net 将数据库中的数据插入表中? - How to insert data from database into a table using c# asp.net? 如何在ASP.NET中的表中插入数据 - How to insert data in table in asp.net 使用Asp.net将数据插入数据库表中 - Insert data in a database table using Asp.net 将数据库大表中的数据绑定到asp.net core中的html表 - bind data from a database large table to html table in asp.net core 批量从GridView向ASP.Net中的postgresql数据库插入数据 - Bulk insert data from GridView to postgresql database in ASP.Net 从ASP.NET将数据插入本地SQL Server数据库 - Insert data into local SQL Server database from ASP.NET ASP.Net将数据从文本框插入数据库 - ASP.Net insert data from Textbox to a database 如何从 HTML 插入 dan 更新值<select>ASP.NET MVC 中的多个属性到数据库? - How to insert dan update value from HTML <select> multiple Attributes in ASP.NET MVC to database? 如何使用ASP.NET MVC将数据从一个数据库表移动到同一数据库的另一表? - How to move data from one database table to another table of same database using ASP.NET MVC? 无法使用angularjs和asp.net Web方法将数据库中的数据显示到html表中 - Unable to display data from the database into html table using angularjs and asp.net webmethod
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM