Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing tables with ASP.Net - Quick 'n Dirty

I have need to provide a way for users to edit tables in ASP.Net. The tables are simple (no master/detail relationships), but there are likely to be a lot of them. What's the quickest/simplest way to provide a view/edit interface to a table, even considering commercial options (but not Iron Speed Designer. That thing is ridiculously expensive for what I need)?

In its most simple/ideal configuration, I'd want to point a control at a table and be done. I've looked at a few ORM solutions, but they all try to be a swiss army knife which just piles on the complexity and tend to be beasts unto themselves.

Is there something that is crazy simple that can help me here? Or should I just dive into SubSonic or something similar?

like image 817
Tim Coker Avatar asked Jun 04 '10 13:06

Tim Coker


3 Answers

After some research, the quickest thing I found turns out to be just using linq to sql with a GridView. I was looking for a solution that can easily integrate into existing pages. Without the benefit of auto-scaffolding and generated pages, Dynamic Data kinda misses the mark. 99% of what I wanted was to avoid getting into writing SQL statements and handling the UpdateCommands manually.

Here are the steps I wrote up for my own personal reference. It relies heavily on the designers, but for what I need, this is perfect:

  1. New project (or existing project)
  2. Add LinqToSqlClass file to project
  3. Add Relevant tables from datasource to design surface (use server explorer)
  4. Build project (so that datacontext class will get generated)
  5. Go to aspx page
  6. Drag a linqdatasource object from toolbox.
  7. Configure datasource (make sure to enable update if necessary)
  8. Drag a gridview from toolbox
  9. Set datasource to linqdatasource object you just created
  10. Customize columns if necessary (ie, set readonly property on non-editable columns, hide non-relevant columns.)

As far as dynamic data is concerned, the documentation is currently lacking. There's a LOT of stuff that references earlier versions that doesn't work quite the same now. I watched the videos here and followed the steps here, but ultimately ran into problems when I tried hiding non-editable columns. The update statement generated by linq didn't reference the primary key and I got the Row not found or changed error. I gave up and used the solution above.

Hope this helps someone else in the future!

like image 80
Tim Coker Avatar answered Nov 03 '22 12:11

Tim Coker


Dynamic Data is a very easy way to edit database tables via ASP.Net. I had absolutely no knowledge of it, but I set up a website to edit a small database in literally 5 minutes, using one of Scott Guthrie's blog posts. It handled the simple foreign key relationships I had as well.

like image 25
Graham Clark Avatar answered Nov 03 '22 14:11

Graham Clark


Try DynamicData from microsoft, built in to asp.net 4, avalable as download for earlier versions.

like image 4
David Waters Avatar answered Nov 03 '22 14:11

David Waters