Skip to content Skip to sidebar Skip to footer

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 browse

Solution 1:

You could create two tables - one for the entry for the Html table as such (with an ID guaranteed to be unique, and a name for the Html table), and another one for the data contained in the table:

CREATETABLE dbo.HtmlTables
(ID INTNOTNULLIDENTITY(1, 1) PRIMARY KEY,
 HtmlTableName VARCHAR(100)  -- or whatever length you need
)

CREATETABLE dbo.HtmlTableData
(ID INTNOTNULLIDENTITY(1, 1) PRIMARY KEY,
 HtmlTableID INTNOTNULL,
 Sequence INTNOTNULL,
 Key INT,
 ValueVARCHAR(500)
)

You'll want to create a foreign key referential integrity between the two tables on the HtmlTables.ID field:

ALTERTABLE dbo.HtmlTableData
  ADDCONSTRAINT FK_HtmlTableData_HtmlTables
  FOREIGN KEY(HtmlTableID) REFERENCES dbo.HtmlTables(ID)

and you most likely also want to make sure each sequence number shows up only once for each HtmlTableID, so create a unique index.

CREATEUNIQUE INDEX UIX01_HtmlTableData
  ON dbo.HtmlTableData(HtmlTableID, Sequence)

Now you could store each HTML table into an entry in dbo.HtmlTables, and each row in the grid can be stored into a row in dbo.HtmlTableData and be associated with the HTML table entry through the foreign key relationship, and it will be sequenced properly by means of the Sequence field.

Post a Comment for "Advice How To Save Html Table To Sql Server"