English 中文(简体)
如何将HTML表格保存到SQL服务器的建议
原标题:advice how to save html table to SQL server

I am trying to save html table to sql server table with unique name and save its data in a database. For example, I have a html table like this(it is dynamically created in browser by user).

int varchar(20) (翻译): int varchar(20)

I use asp.net, C#, Sql Server 2008 express. How can after clicking on save button, create table with unique name, 2 colums int and varchar(40) types, and insert data?

我认为可以通过将表格渲染为XML,然后在C#类上处理该XML,然后保存到数据库中。

你唱的是什么?

编辑后添加?

我想要保存这个。

    <table>
        <tr>
           <td>int</td>
           <td>varchar(40)</td>
        </tr>
        <tr>
           <td>1</td>
           <td>USA</td>
        </tr>
        <tr>
           <td>2</td>
           <td>Canada</td>
        </tr>
        <tr>
           <td>3</td>
           <td>Mexico</td>
        </tr>
    </table>

像这样:

CREATE TABLE uniqueName
(key int,
values varchar(50)) 

INSERT INTO uniqueName (key, values)
       VALUES (1,   USA ) 
INSERT INTO uniqueName (key, values)
       VALUES (2,   Canada ) 
INSERT INTO uniqueName (key, values)
       VALUES (3,   Mexico ) 

会帮助代码的和平更多:)或链接

最佳回答

您可设立两个表格:一个表格用于Html表格的输入(有ID保证为独一无二,另一个表格是Html表格的名称);另一个表格中的数据:

CREATE TABLE dbo.HtmlTables
(ID INT NOT NULL IDENTITY(1, 1) PRIMARY KEY,
 HtmlTableName VARCHAR(100)  -- or whatever length you need
)

CREATE TABLE dbo.HtmlTableData
(ID INT NOT NULL IDENTITY(1, 1) PRIMARY KEY,
 HtmlTableID INT NOT NULL,
 Sequence INT NOT NULL,
 Key INT,
 Value VARCHAR(500)
)

你需要在两个表之间的HtmlTables.ID字段上创建外键参照完整性。

ALTER TABLE dbo.HtmlTableData
  ADD CONSTRAINT FK_HtmlTableData_HtmlTables
  FOREIGN KEY(HtmlTableID) REFERENCES dbo.HtmlTables(ID)

你很可能还希望确保每个HtmlTableID的序列号只出现一次,因此要创建一个唯一索引。

CREATE UNIQUE INDEX UIX01_HtmlTableData
  ON dbo.HtmlTableData(HtmlTableID, Sequence)

现在,你可将每张超文本表格储存在<条码>dbo.HtmlTables的条目中,电网的每行都可以储存在<条码>dbo.HtmlTableData上,并通过外国关键关系与超文本条目挂钩,并将通过<条码>Sequence的外地适当排序。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签