by Santi Mondejar (2 Submissions)
Category: Active Server Pages
Compatability: ASP (Active Server Pages)
Difficulty: Unknown Difficulty
Originally Published: Mon 31st July 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This script is a pseudo wizard, that allows to generate automatically an HTML form from a SQL query. Additionally, inserts the data contained
<% if len(Request.QueryString) = 0 then
'First call
Set db_cnx = Server.CreateObject("ADODB.Connection")
db_path="DBQ=" & server.mappath("db1.mdb")
Session("source")= db_path
db_cnx.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & Session("source")
Sql1 = " SELECT * FROM some_table "
Session("sql")=Sql1
Set db_rcdst1 = Server.CreateObject("ADODB.Recordset")
db_rcdst1.Open Session("sql"), db_cnx, 1, 2
%>
<form action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="get" >
<table border>
<% for i=0 to db_rcdst1.fields.count-1 %>
<td><%=db_rcdst1(i).name %></TD><TD><input type=text name=<%=db_rcdst1(i).name %> size=<%=db_rcdst1(i).definedsize %>>
</TD><tr>
<%next%>
</tr><td colspan=2><input type="submit"></td></form></table>
<% Else
'Second call
Set db_cnx = Server.CreateObject("ADODB.Connection")
db_cnx.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & Session("source")
Set db_rcdst1 = Server.CreateObject("ADODB.Recordset")
db_rcdst1.Open Session("sql"), db_cnx, 1, 2
Set db_rcdst2 = Server.CreateObject("ADODB.Recordset")
db_rcdst2.Open Session("sql"), db_cnx, 1, 2
'starting database writing
db_rcdst1.AddNew
a=db_rcdst1.fields.count
For Each Key In Request.QueryString
a=a-1
val_type=Request.QueryString(key)
obj_width = db_rcdst2(a).definedsize
clase = db_rcdst2(a).type
Select case clase rem VarType(db_rcdst2(a))
Case 2
val_type = Cint(val_type)
Case 3
val_type = Clng(val_type)
Case 4
val_type = Csng(val_type)
Case 5
val_type = Cdbl(val_type)
Case 6
val_type = Ccur(val_type)
Case 135
If IsDate(val_type) Then
val_type = Cdate(val_type)
Else val_type=Date
End If
Case 200
var_type="Cstr"
val_type = Cstr(Left(val_type, obj_width))
Case 11
If Ucase(val_type) = "true" Then
val_type = True
Else
val_type = False
End If
Case 17
var_type="Cbyte"
val_type = Cbyte(val_type)
End Select
db_rcdst1(a)=val_type
Next
db_rcdst1.Update
db_rcdst1.Close
db_rcdst2.Close
Set db_rcdst1 = Nothing
Set db_rcdst2 = Nothing
Session.Abandon
Response.Write("information have been registered")
finish=True
End If%></BODY></HTML>
No comments have been posted about This script is a pseudo wizard, that allows to generate automatically an HTML form from a SQL query. Why not be the first to post a comment about This script is a pseudo wizard, that allows to generate automatically an HTML form from a SQL query.