SQL7 to ASP From Code Generator?

Results 1 to 2 of 2

Thread: SQL7 to ASP From Code Generator?

  1. #1
    Join Date
    Dec 1969

    Default SQL7 to ASP From Code Generator?

    OK- I have a SQL7 DB with over 130 fields. I need a code generator that will write an ASP form to Update the DB. Anyone know where to get this? It&#039s a HUGE help...<BR>Damon

  2. #2
    Join Date
    Dec 1969

    Default Any DB to edit-a-record code?

    ...where to get this?<BR><BR>How about writing one? It&#039s pretty easy:<BR><BR>First, you need an ASP page that allows the user to select a record to update. You will have to figure out what you need there! Will you have them type in a name? an ID? Select from a drop down list? Show key data from all records and have them click on a button?<BR><BR>But now you have the criteria to select a single record. How do you display an update form? That part&#039s pretty easy:<BR><BR>&#060;%<BR>SQL = "SELECT * FROM table WHERE ...criteria you decide on..."<BR>Set RS = yourConnection.Execute( SQL )<BR>If RS.EOF Then<BR> &nbsp; Response.Write "something did not work in the query"<BR> &nbsp; Response.End<BR>End If<BR><BR>For fnum = 0 To RS.Fields.Count - 1<BR> &nbsp; fname = RS.Fields(fnum).Name<BR> &nbsp; Response.Write "Field " & fname & ": "<BR> &nbsp; If RS.Fields(fnum).Type = adDouble Then fname = "#" & fname &#039 SEE COMMENTS<BR> &nbsp; Response.Write "&#060;INPUT Name=&#039" & fname & "&#039 Value=&#039" & RS.Fields(fnum) & "&#039 SIZE=60&#062;&LT;BR&#062;" & vbNewLine<BR>Next<BR><BR>%&#062;<BR><BR>You might want to clean that up some: If the field is a true/false field, then present it as a checkbox, perhaps. <BR><BR>And you probably want to drop in validation code, too. Example: if a field is specified in the DB as numeric, don&#039t allow any non-numeric input.<BR><BR>But the idea there is simple enough. Just loop through all the fields, in order.<BR><BR>NOW... in the next page, you can simply do:<BR><BR>&#060;%<BR>SQL = "UPDATE table SET "<BR>DELIM = " "<BR>For Each Item in Request.Form<BR> &nbsp; If Left(Item,1) = "#" Then<BR> &nbsp; &nbsp; SQL = SQL & DELIM & "[" & Mid(Item,2) & "]=" & Request.Form(Item)<BR> &nbsp; Else<BR> &nbsp; &nbsp; SQL = SQL & DELIM & "[" & Mid(Item,2) & "]=&#039" & Request.Form(Item) & "&#039"<BR> &nbsp; End If<BR> &nbsp; DELIM = ","<BR>Next<BR>%&#062;<BR><BR>See it? In the FORM page, we added a # to the front of a numeric field. In my code, I show only testing against adDouble, but obviously you would actually test against any of the numeric field types.<BR><BR>You might want to use other special characters to indicate other data types. ($ to indicate currency? Not sure currency needs to be treated differently than numeric, though. But you get the idea.)<BR><BR>If you really wanted to, you could keep the original value of each field in a TYPE=HIDDEN form field, again using a special prefix for such fields, and compare the non-hidden value versus what you know is the original, so that you don&#039t bother to try to update unchanged fields. That doesn&#039t seem to me to be necessary, though.<BR><BR>Anyway, with just a bit of care and attention to the screen format and possible data types, I think you can produce a general purpose edit page with relatively little work!<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts