Welcome to the CodeSmith Community!

Simple Web-based DB Editor (CRUD builder)

File Share

A description has not yet been added to this group.

Simple Web-based DB Editor (CRUD builder)

  • rated by 0 users
  • This post has 9 Replies |
  • 5 Followers
  • SortableEditor.zip
    Attached is a simple DB Editor that hooks up to a database and creates a nice table/edit form. The table is based on the datagrid, is sortable, and has a column filter built in so users can find what they want fast. I finally got around to polishing up a routine that i use literally on a daily basis!
     
    This template is built using SqlClient; however the base interactions use a DataTable so to use the OleDbClient it requires small modifications. It also uses the SqlCommandBuilder with a SqlDataAdapter which is nice because it protects you (hopefully) from most SQL Injection routines. 
     
    The story behind this is this: I have been doing this for a long time, and creating data pages can be tedious (at best) even with a good template to work from. This template is built to hook up and run from the start; you won't need to change anything if all you want is to put data into a DB with some CRUD hookups. If you have bigger things in mind, this will get you to 90% at least.
     
    You can choose to let the page put the data to the DB for you, or you can alter it to push the results to a facade or rule object. The save routine creates a datatable and binds it - you can modify the output to send the routine to a facade if you like, or implement your own Validation Routine (unique emails e.g.).
     
    The ASPX page template creates controls based on the data type - a Calendar for date fields, a small textbox (with numeric validator) for numeric fields, a drop down for any int field with the letters "ID" (foreign key guess), a multi-line textbox for a field whose length is >200, etc.
     
    The Code-Behind template should work straight off, provided you keep your DB Connection String in your Web.Config file.
     
    There are 2 templates attached: one for the aspx page, one for the code. To use this:
    1) Run the SortableEditor template to create the ASPX page
    2) Edit the output to look the way you like and rename the label fields (they are defaulted to the name of the field)
    3) Run the SortableEditorCode template and paste it into the code-behind page. You won't need to modify this at all unless you want to add some validation etc.
     
    Hope this works out for you - please let me know if you tweak it and how - would love to see the changes!
     
    PS: Yes, I looked for a JS Calendar, but it flipped out the template so you may want to alter this to use your JS Calendar of choice. No, i am not a big fan of the calendar control either but it works nicely for this purpose :).

    Post Edited (spookytooth) : 1/25/2005 10:49:27 PM GMT

  • Im liking what I see so far but I cant get it to work. I get an error on this code


            void ThrowError(Common.Data.ExceptionData Exceptions)
            {
                trError.Visible=true;
                Exceptions.Rewind();
                while(Exceptions.MoveNext())
                {
                    lblError.Text+=Exceptions.Message+"
    ";
                }

            }


    Where does the "common" come from?
    Zachary Kent
    Director of IT

    R. J. Peters Associates, Inc.

    www.avmax.net
  • That would qualify as a "duh" on my part... Common is a ... well common Assembly i use for Business Object data (like Common.Data.Books in Duwamish). Anyway - it also holds an error result set, which of course you don't have!@

    You can remove the code there and it should compile - i'll repost it sans the Common reference :)

  • hello,
     
    i love the idea of this... but i think you forgot to give these unique names...
     
    Parser Error Message: The ID 'RangeValidator1' is already used by another control.

    Source Error:

    Line 172:											<asp:textbox id="txtLOT" runat="server"
    Line 173:											></asp:textbox>
    Line 174:										<asp:RangeValidator id="RangeValidator1" runat="server" Display="Dynamic" ControlToValidate="txtLOT"
    Line 175:										ErrorMessage="Invalid Number" MaximumValue="99999999" MinimumValue="0" Type="Integer"></asp:RangeValidator>
  • spookytooth said...
    That would qualify as a "duh" on my part... Common is a ... well common Assembly i use for Business Object data (like Common.Data.Books in Duwamish). Anyway - it also holds an error result set, which of course you don't have!@

    You can remove the code there and it should compile - i'll repost it sans the Common reference :)


    Also I think both scripts are generating some of the same code for the codebehind. Specifically the following section,

    #region Web Form Designer generated code
    Zachary Kent
    Director of IT

    R. J. Peters Associates, Inc.

    www.avmax.net
  • Nice catch! You are right - i have changed this to dynamically name the validator for the numbers :) (Attached above).
  • also for this:

    3) Run the SortableEditorCode template and paste it into the code-behind page. You won't need to modify this at all unless you want to add some validation etc.

    do you seriously not have to do anything ? I thought you had to put in at least the source table (i did). And what about the WebConfigDBKey ?
  • Yes, you do have to enter the params for the template - i was referring to modifying the output once the template is run. To rephrase:
    You won't need to modify the output at all unless you want to add some code validation to fit your processes (like a commerce app would want users with unique emails before adding them).

    Thanks for testing this out :) - lemme know if you have any more issues.
  • i can't seem to get this working...  it was almost working yesterday =/
     
    i admit im a bit of a .net noob, but i thought i was doing this right.
    i ran codesmith to generate all the code for front and backend... i start a new asp.net web app in vs.net 2003, i paste the front end stuff in the aspx page and right click->code behind and paste all the back end stuff in the public class ProjectName { }. 
     
    i get all these "The type or name 'ddHeaders' could not be found" type errors, which i know are because the elements haven't been declared at the top.  but i thought this was done automaticly when the .cs page was created ?
    ie:
    protected System.Web....Panel pnlPanel1; etc.
     
    And do i have to include using System.Data.SqlClient for SqlDataReader (in BindDropDown)?
     
    also: do you know of anything like this for straight asp? (classic asp 3.0)
     
    thanks much.
     
    [i]edited: Ok.. clicking the Design tab seemed to fill in all the declarations i needed.[/i]

    Post Edited (dood) : 1/27/2005 4:25:23 PM GMT

  • A good point to add - paste the ASPX bits into the page then click on the design tab to fill in the control bits. I'll add the control creation into the next rev here (tonite maybe); i was thinking it would be easier to ahve the page pop the controls in there.

    You should include the using statement - yes :).
  • SortableEditor050222.zip
    Spookytooth thank you for these templates a real timesaver!
    I have attached a new build.
    I found a bug, that prevented Add from saving, with the SortableEditorCode where the BuildTable had hardcoded fields.  I fixed this so the fields are based on the selected table.
    I also updated the SortableEditor so that the maxlength gets set on strings, preventing the user from entering too many characters.
    I just got started with CodeSmith a couple days ago, if I overlooked anything critical please let me know.
  • I just noticed that "little issue" just the other day. A little bug introduced when updating this template with changes.
     
    Thanks for your post; i have updated the original DL as well! jumpin
  • Pretty nice.

    However, I had two problems in the code-behind because my table key was not a number. I had to comment out the AutoIncrement line

    //column.AutoIncrement=true;

    and I had to add apostrophes around the editID:

    System.Data.DataTable tbl=GetData("SELECT * FROM adult_override WHERE V_id='"+editID+"'");

    Thanks for the work!

    Gary
  • Excellent! thanks for adding this addition; i am so used to int keys that i flat out didn't consider strings... i spose there is no need to have it... just habit!

    Thanks,
    Rob
  • SortableEditorCodeVB.zip
    I've modified the code to work w/VB. It works great - unless you have a date field. The only problem if you have a date field is that when you edit/add a new entry, the page does not refresh to the main grid - the entry is added/updated, but you're still on the subgrid. Any thoughts?
     
     
     
     
Page 1 of 2 (22 items) 12