基于 Web 的 .NET SQL 数据库管理器
我有一个 ASP.NET 项目,想要创建一个页面,系统管理员可以在其中修改数据库表数据(插入、更新和删除行)。
首先,我有一个基于数据库中的表进行数据绑定的下拉菜单:
DdlTable.DataSource = from x in dc.Mapping.GetTables()
orderby x.TableName.Replace("dbo.", "")
select new {TableName = x.TableName.Replace("dbo.", "")};
DdlTable.DataTextField = "TableName";
DdlTable.DataValueField = "TableName";
DdlTable.DataBind();
DdlTable.Items.Insert(0, "Select a Table");
接下来,我想要一个在选择时绑定到表的 gridview (或其他一些数据对象),并具有列、插入、动态构建的更新和删除功能。可以在不为每个特定表编码的情况下完成此操作吗?
显然,我可以创建 x 个网格视图和数据源,但我希望动态构建它以实现灵活性和最少的编码。
本质上,我想要一个简单的基于 Web 的 SQL 管理器。
I have an ASP.NET project and would like to create a page where my system admins can modify database table data (insert, update, and delete rows).
First, I have a drop down that is databound based on the tables in the database:
DdlTable.DataSource = from x in dc.Mapping.GetTables()
orderby x.TableName.Replace("dbo.", "")
select new {TableName = x.TableName.Replace("dbo.", "")};
DdlTable.DataTextField = "TableName";
DdlTable.DataValueField = "TableName";
DdlTable.DataBind();
DdlTable.Items.Insert(0, "Select a Table");
Next, I would like to have a gridview (or some other data object) that is bound to a table upon selection, and have the columns, insert, update, and delete functionality built dynamically. Can this be done without coding for each specific table?
Obviously, I can create x number of gridviews and datasources, but I would like it to be built dynamically for flexibility and minimal coding.
Essentially, I want to have a simple web-based SQL manager.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试...
为每个表创建一个单独的数据源(在代码或标记中,无关紧要)。
确保页面加载时 gridview 没有设置数据源。
在某些事件(按钮单击、下拉列表的 selectedindexchanged 等)中,将 gridview 的数据源设置为下拉列表中选择的数据源,确保 autogenerate = true,然后使用 databind()。
Try...
Create a seperate datasource for each table (in code or mark-up, doesn't matter).
Make sure the gridview doesn't have a datasource set when the page loads.
On some event (button click, selectedindexchanged of your dropdown, etc.), set the gridview's datasource to whichever datasource is selected in the dropdown, make sure autogenerate = true, and then databind().
简而言之 - 不 - 你改变了你的表,你必须改变你的 CRUD - 没有灵丹妙药。
你可以尝试类似 CodeSmith 的东西。或者你可以自己写一些东西——应该不会太难,不是吗?查询表字段的 InformationSchema 视图,您就拥有了在代码隐藏中构建函数以生成 CRUD 语句所需的所有信息。
In short - no - you change your tables, you have to change your CRUD - there's no magic bullet.
You can try something like CodeSmith. Or you can just write something yourself -- shouldn't be too difficult, should it? Query the InformationSchema view for your table's fields and you have all of the information you need to build a function in your code-behind to generate the CRUD statements.