输入值,从“无限”动态控件数据库 [英] Entering values into database from 'unlimited' dynamic controls

查看:113
本文介绍了输入值,从“无限”动态控件数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有就是从那里用户选择他想要的文本框的数量1-10显示一个下拉 - 如果他选择是无限的,它显示了他一个文本框,其中他进入他想文本框的确切数目。如果他进入40,它显示了在运行时创造了他40文本框。

There's a dropdown displaying 1-10 from where the user selects the number of textboxes he wants - if he chooses unlimited, it shows him a textbox wherein he enters the exact number of textboxes he'd like. if he enters 40, it shows him 40 textboxes which are created at runtime.

我的问题是,我该如何进入40数据 - 或者'他进入任何号码文本框到MS SQL数据库。有没有办法,我可以动态创建一个列名,那会是过于繁琐和杂乱。有没有什么办法可以做到这一点?

My question is, how do I enter the data from 40 - or 'whatever number he enters' textboxes into the MS SQL database. There's no way I can create a column name dynamically, and that'd be too tedious and messy. Is there any way I can do this?

推荐答案

你有什么是1对多的关系,无论之间的话,将是该网页,评论或说明或任何上。你不应该这样仿照你的数据库text_box_1,text_box_2等相反,它应该是:

What you have is a 1-to-many relationship between whatever it is that is on that page and the comments or descriptions or whatever. You shouldn't have this modeled in your database as text_box_1, text_box_2, etc. Instead, it should be:

CREATE TABLE Some_Entity
(
    some_entity_id	INT	NOT NULL,
    CONSTRAINT PK_Some_Entity PRIMARY KEY CLUSTERED (some_entity_id)
)
GO

CREATE TABLE Some_Entity_Comments
(
    some_entity_id	INT		NOT NULL,
    comment_number	INT		NOT NULL,
    comments		VARCHAR(1000)	NOT NULL,
    CONSTRAINT PK_Some_Entity_Comments
     	 PRIMARY KEY CLUSTERED (some_entity_id, comment_number),
    CONSTRAINT FK_Some_Entity_Comments_Some_Entity
     	 FOREIGN KEY (some_entity_id) REFERENCES Some_Entity (some_entity_id)
)
GO

一旦这样做了,你可以使用类似于门写来处理前端的东西code。你只是通过文本框指数作为comment_number。

Once that's done, you can use code similar to what Mun wrote to handle things on the front end. You'll just pass the text box index as the comment_number.

这篇关于输入值,从“无限”动态控件数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆