开发者

Web-based .NET SQL database manager

I have an ASP.NET project a开发者_如何学Cnd 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.


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().


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜